Strings

=Strings=

A string is a collection of characters often represented by an array of chars. Depending on the programming language, a string may be statically initialized with a set max length or dynamic. Strings can be used to story any amount of information such as names in a data base.

In C++
Creating a string in C++ can be done in two ways; creating an array of chars or using the string.h library. The string.h library includes a number of useful functions: code format="cpp"
 * Function || Effect ||
 * int size || returns the length of the string ||
 * bool empty || tests if a string is empty ||
 * void append(string) || append to string ||
 * void replace(int, int, string) || a section of the string is replaced ||
 * void copy(char[], int, int) || copy a part of a string to a char array ||
 * int find(string) || returns the position of the first occurrence in the string ||
 * See more: || [|here] ||
 * 1) include
 * 2) include

main{ char myString[] = "Hello World!";

string anotherString("World says Hello."); int length = anotherString.size; //18

printf("%s\n%s has size %d", myString, anotherString, length); } code

In Java
Creating a string in java is done through the String class. Many classes in Java have a toString function that returns a string relevant to the information in the class. It also has many useful functions found [|here]. code format="java" public class StringDemo{ public static void main(String[] args){ String myString = "Hello "; String finalString = myString + "World!"; //append world to mystring

System.out.println(finalString); } } code