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);
The substring returned by the substring () method includes the character at start, but does not include the character at the end.
If the argument start is equal to end, then the method returns an empty string (that is, the length 0). If start is larger than end, the method swaps the two parameters before extracting the substring.
2 Remove the first I characters of the string:
Str=str.remove (0,i); or str=str.substring (i);
Remove method
Deletes a primary key from a Dictionary object, and the entry pair.
Object.remove (Key)
Parameters
Object
Required option. Always the name of a Dictionary object.
Key
Required option. Key is associated with the primary key that you want to remove from the Dictionary object.
Description
If the specified primary key, the entry pair does not exist, it will cause an error.
The following code illustrates the use of the Remove method:
var A, D, I, S; Create some variables. D = new ActiveXObject ("Scripting.Dictionary
3 Starting from the right I character:
Str=str.substring (str.length-i); or Str=str.remove (0,str.length-i);
4 from the right start to remove the I characters:
Str=str.substring (0,str.length-i); or Str=str.remove (str.length-i,i);
5 Determine if there is an "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 can be taken one.
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 "ABC" is replaced with "ABC" in the string
Str=str.replace ("abc", "abc");
String str= "Adcdef"; int indexstart = Str.indexof ("D");
int Endindex =str.indexof ("E");
This method retrieves the string stringobject from beginning to end to see if it contains substring searchvalue. The location at which to start retrieving is at the fromindex of the string or at the beginning of the string (no fromindex is specified). If a searchvalue is found, it returns the position of the first occurrence of searchvalue. The character position in the Stringobject is starting at 0.
Tips and comments
Note: the IndexOf () method is case sensitive!
Note: If the string value to retrieve does not appear, the method returns-1.
String tostr = Str.substring (Indexstart,endindex-indexstart);
C # intercepts the last character of the string problem!
Str1.substring (Str1.lastindexof (",") +1)