Dictionary of Computer and Internet Terms: string operations
string operations
operations that are performed on character string data. Here are some examples from Java, where A represents the string "GEORGE" and B represents "WASHINGTON"
- Compare two strings to see if they are the same. For example,A.equals(B)
(in other programming languages, A==B or A=B) will be false. - Determine if one string comes before the other in alphabetical order. For example,
A. compareTo(B)<=0
will be true (because GEORGE comes before WASHINGTON). In other programming languages this is expressed as Asee Unicode). - Join strings together (concatenation). For example,
A+" "+B
is
"GEORGE WASHINGTON"
created by joining A, a blank, and B. - Calculate the length of a string. For example, A.length () is 6.
- Select specified characters from any position in string. For example,
B.substring(4,7)
is the string "ING". The 4 means to start at character 4, which is the character I since the first character (W) is character 0. The 7 means to include all characters up to (but not including) character 7 (which is T). - Determine if one string is contained in another string, and if so, at what position it starts. For example,
A.indexOf("OR")
is 2, since OR starts at character 2 of GEORGE (recall that the first character is character 0). However,
B.indexOf("AND")
is -1 since the string AND does not occur within the string WASHINGTON. - Determine the Unicode value for an individual character. For example, if C is a character variable, then (short) C
will give its Unicode value. Here short is a type of integer variable. - Determine the character associated with a given Unicode value. For example, if K is an integer variable, then
(char)K
is the character associated with that value. - Determine the numerical value of a string that represents a number. Here are two example for integers and strings):
String x="234";
int z=Integer.parseInt(x);
String x2="234.567";
double z2=(Double.valueOf(x2)).doubleValue();
Note the capitalization needs to be exactly as shown. - Convert a numeric value into a string. For example,
String x=String.valueOf(567);
will cause x to become the string "567".