The earthquake just happened. It may be too small. I don't feel it ~~~~~
Today, I calmly learned some operations on strings. I want to use them, so even though they are all the most basic operations, remember them.
Including:
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
Code As follows: Class Program
{
Static Void Main ( String [] ARGs)
{
Console. writeline ( " ------------------- Test join " );
String Str = "" ;
String [] strarr = {"Aaa","Bbb","CCC"} ;
Str = String. Join ( " + " , Strarr );
Console. writeline (STR );
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 ));
Console. writeline ( " ------------------- Test indexof " );
Console. writeline (Str. indexof ( ' L ' ));
Console. writeline ( " ------------------- Test split " );
Strarr = Str. Split ( ' + ' );
Int I = 0 ;
While (I < Strarr. length) {
Console. writeline (strarr [I]);
I++;
}
Console. writeline ( " ------------------- Test padleft " );
Str = " Hello " ;
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 );
Console. writeline (STR );
}
}
Next, let's look at stringbuilder.