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");
7. How to intercept the characters in front of the specified characters and the following characters in the string
String str = "Key:value:other";
string[] STRs = Str.split (":");
key = Strs[0];
Value = Strs[1];
other = strs[2];
************************************************
String str= "Adcdef"; int indexstart = str. IndexOf ("D");
int EndIndex =str. IndexOf ("E");
string tostr = str. SubString (Indexstart,endindex-indexstart);
C # intercepts the question of the last character of a string!
Str1. Substring (str1. LastIndexOf (",") +1)
This article is from the "Liangxiao Technology Center" blog, please be sure to keep this source http://liangxiao.blog.51cto.com/3626612/1949055
Android Studio-Interception of several commonly used strings in the 42nd issue