Original: C # intercept string
The interception of several commonly used stringsstringStr="123abc456";intI=3;1takes the first I character of a string str=str. Substring (0, i);//or STR=STR. Remove (i,str. LENGTH-I);2Remove the first I character of a string: str=str. Remove (0, i);//or STR=STR. Substring (i);3start from the right to take I characters: Str=str. Substring (str. LENGTH-I);//or STR=STR. Remove (0,str. LENGTH-I);4Remove I characters from the right: Str=str. Substring (0Str. LENGTH-I);//or STR=STR. Remove (str. Length-i,i);5Determine if there is a string in the"ABC"If there is one, remove it .usingSystem.Text.RegularExpressions; stringstr ="123abc456"; stringA="ABC"; Regex R=NewRegex (a); Match m=R.match (str); if(m.success) {//the green part and the purple part take one kind. Str=str. Replace (A,""); Response.Write (str); stringstr1,str2; STR1=str. Substring (0, M.index); STR2=str. Substring (m.index+a.length,str. length-a.length-M.index); Response.Write (str1+str2); }6If the string has"ABC"is replaced by"ABC"Str=str. Replace ("ABC","ABC"); ************************************************stringStr="Adcdef";intIndexstart = str. IndexOf ("D");intEndIndex =str. IndexOf ("e");stringTostr = str. SubString (indexstart,endindex-indexstart); C # intercepts the last character of a string!str1. Substring (str1. LastIndexOf (",")+1)
C # Intercept string