String str= "123abc456";
int i=3;
1 Take the first I character of a string
Str=str. Substring (0,i); or STR=STR. Remove (i,str. LENGTH-I);
2 Remove the first I character of a string:
Str=str. Remove (0,i); or STR=STR. Substring (i);
3 Take I characters starting from the right:
Str=str. Substring (str. LENGTH-I); or STR=STR. Remove (0,str. LENGTH-I);
4 Remove the I characters starting from the right:
Str=str. Substring (0,str. LENGTH-I); or STR=STR. Remove (str. Length-i,i);
5 Determine if there is "ABC" in the string and remove it
Using System.Text.RegularExpressions;
String str = "123abc456";
String a= "abc";
Regex r = new Regex (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);
String str1,str2;
Str1=str. Substring (0,m.index);
Str2=str. Substring (m.index+a.length,str. Length-a.length-m.index);
Response.Write (STR1+STR2);
}
6 If there is "ABC" in the string, replace it with "ABC"
Str=str. Replace ("abc", "abc");
Interception of several commonly used strings (Java)