1. Split intercept based on a single delimiter character
For example
String st= "Gt123_1";
String[] Sarray=st.split ("_");
Can get sarray[0]= "GT123", sarray[1]= "1";
2. Separating strings with multiple characters
For example
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 to intercept a string based on a string or string group
For example
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 extracts the string of the first character of the string beginning with the length of J;
For example
String str = "gtazb_jiangjben_123";
int start=3,length=8;
Console.WriteLine (str. Substring (start-1, length));
The output gets Azb_jian.
5 extracting the string with the right-length I in the string
String str = "gtazb_jiangjben_123";
String tSt;
int i=5;
TSt = str. Substring (str. LENGTH-I);
Console.WriteLine (tSt);
Output n_123;
6 replacing a specific string in a string
String str = "gtazb_jiangjben_123";
String tSt;
TSt = str. Replace ("123", "321");
Console.WriteLine (tSt);
Output gtazb_jiangjben_321
7 delete a specific string in a string jiangj
String str = "gtazb_jiangjben_123";
String tSt;
TSt = str. Replace ("Jiangj", "" ");
Console.WriteLine (tSt);
Output gtazb_ben_123
8 Delete A string of the specified length (length) for the specified position (i)
String str = "gtazb_jiangjben_123";
int i=5,length=8;
Str=str.remove (i,length);
Console.WriteLine (str);
C # Intercept string