1. Use split to intercept a single Separator
For example
Copy codeThe Code is as follows: string st = "GT123_1 ";
String [] sArray = st. split ("_");
You can get sArray [0] = "GT123", sArray [1] = "1 ";
2. Use multiple characters to separate strings
For example
Copy codeThe Code is as follows: string str = "GTAZB_JiangjBen_123 ";
String [] sArray = str. Split (new char [2] {'J ','_'});
Foreach (string e in sArray)
{
Console. WriteLine (e );
}
Get sArray [0] = "GTAZB", sArray [1] = "Jiang", sArray [2] = "Ben", sArray [3] = "123 ";
3. truncate a string based on a string or a string Group
For example
Copy codeThe Code is as follows: string str = "GTAZB_JiangjBen_123 ";
String [] sArray = str. Split (new string [] {"Ji", "jB"}, StringSplitOptions. RemoveEmptyEntries );
Foreach (string e in sArray)
{
Console. WriteLine (e );
}
Get sArray [0] = "GTAZB _", sArray [1] = "ang", sArray [2] = "en_123 ";
4. Extract the string whose length starts from the I character to j;
For example
Copy codeThe Code is as follows: string str = "GTAZB_JiangjBen_123 ";
Int start = 3, length = 8;
Console. WriteLine (str. Substring (start-1, length ));
Output AZB_Jian.
5. Extract the string whose right number is I.
Copy codeThe Code is as follows: string str = "GTAZB_JiangjBen_123 ";
String tSt;
Int I = 5;
TSt = str. Substring (str. Length-I );
Console. WriteLine (tSt );
Output n_123;
6. Replace the specified string in the string
Copy codeThe Code is as follows: string str = "GTAZB_JiangjBen_123 ";
String tSt;
TSt = str. Replace ("123", "321 ");
Console. WriteLine (tSt );
Output GTAZB_JiangjBen_321
7. Delete the specified string Jiangj.
Copy codeThe Code is as follows: string str = "GTAZB_JiangjBen_123 ";
String tSt;
TSt = str. Replace ("Jiangj ","");
Console. WriteLine (tSt );
Output GTAZB_Ben_123
8. Delete the string of the specified length (length) at the specified position (NTH ).
Copy codeThe Code is as follows: string str = "GTAZB_JiangjBen_123 ";
Int I = 5, length = 8;
Str = str. remove (I, length );
Console. writeline (str );
Output GTAZBen_123.