String STR = "123abc456 ";
Int I = 3;
1. Take the first I character of the string.
STR = Str. substring (0, I); // or str = Str. Remove (I, str. Length-I );
2 remove the first I character of the string:
STR = Str. Remove (0, I); // or str = Str. substring (I );
3. Start from the right side with I characters:
STR = Str. substring (Str. Length-I); // or str = Str. Remove (0, str. Length-I );
4. Remove the I characters from the right:
STR = Str. substring (0, str. Length-I); // or str = Str. Remove (Str. Length-I, I );
5. If "ABC" exists in the string, remove it.
Using system. Text. regularexpressions;
String STR = "123abc456 ";
String A = "ABC ";
RegEx r = new RegEx ();
Match m = R. Match (STR );
If (M. Success)
{
// Take one of the two below.
STR = Str. Replace (,"");
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 the string contains "ABC", replace it with "ABC"
STR = Str. Replace ("ABC", "ABC ");
**************************************** ********
String STR = "adcdef"; int indexstart = Str. indexof ("D ");
Int endindex = Str. indexof ("e ");
String tostr = Str. substring (indexstart, endindex-indexstart );
C # The question of intercepting the last character of a string!
Str1.substring (str1.lastindexof (",") + 1 );
C # truncate the last character of the string
K = K. substring (K. Length-1, 1 );