1. Comparison string: Compare, compareto, equals, = ,! =
2. Positioning characters and substrings: startwith/endswith, indexof/lastindexof, indexofany/lastindexofany
3. format the string: Format
4. connection string: Concat, join, +
5. Split string: Split
6. insert and fill strings: insert, padleft/pagright
7. Delete and cut strings: Remove, TRIM/trimstart/trimend
8. Copy strings: Copy and copyto
9. Replace string: replace
10. Change the case sensitivity: toupper/tolower console. writeline ("----------------- test join ");
String STR = "";
String [] strarr = {"AAA", "BBB", "CCC "};
STR = string. Join ("+", strarr );
Console. writeline (STR); // STR = "AAA + BBB + CCC"
Console. writeline ("------------------- test format ");
String stra = "hello ";
String strb = "world ";
STR = string. Format ("{0}, {1 }! ", Stra, strb );
Console. writeline (STR );
Console. writeline ("------------------- test compareto ");
Console. writeline (stra. compareto (strb); //-1
Console. writeline ("ABC". compareto ("ABC"); // 0
Console. writeline ("ABC". compareto ("abcded"); //-1
Console. writeline ("ABCDE". compareto ("ABC"); // 1
Console. writeline (string. Compare ("ABC", "ABC"); // 0
Console. writeline (string. Compare ("abdddc", "ABC"); // 1
Console. writeline (string. Compare ("Abd", "abcdd"); //-1
Console. writeline ("------------------- test indexof ");
Console. WriteLine (str. IndexOf ('l '));
Char [] aaa = {'E', 'h', 'O '};
Console. WriteLine (str. IndexOfAny (aaa); // indexes of any character in aaa and the first matching item in str. The result is 0.
Console. WriteLine (str. LastIndexOfAny (aaa); // index of any character in aaa and the last matching item in str. The result is 1.
Console. WriteLine ("------------------- test Split ");
StrArr = str. Split (','); // The Split string is: strArr [0] = hello strArr [1] = world
Int I = 0;
While (I <strArr. Length)
{
Console. WriteLine (strArr [I]);
I ++;
}
Console. WriteLine ("------------------- test PadLeft ");
Str = "hello ";
Str = str. PadLeft (20, '*'); // 20 indicates the total length of the filled string.
Str = str. PadLeft (20 ,'*');
Console. WriteLine (str );
Console. WriteLine ("------------------- test Remove ");
Str = "abcdefg ";
Str = str. Remove (1, 3 );
Console. WriteLine (str );
Console. WriteLine ("------------------- test Trim ");
Str = "% hello & $ #";
Char [] trmchar = {'%', '&', '$ ','#'};
STR = Str. Trim (trmchar );
STR = Str. trimstart (trmchar); // only delete the starting trmchar value and the result is Hello & $ #
STR = Str. trimend (trmchar); // Delete only the trmchar value at the end, and the result is % Hello.
String str1 = string. Copy (STR );
Console. writeline (STR );