IndexOf ()
Finds the first occurrence of a specified character or string in a string, and returns the first index value, such as:
Copy Code code as follows:
Str1. IndexOf ("word");//Find the index value (position) of the word in str1
Str1. IndexOf ("string");//Find the index value (position) of the first character of the string in str1
Str1. IndexOf ("word", start,end)//from str1 start+1 characters, find the end character, find the position of "word" in the string STR1 [from the first character] Note: Start+end cannot be greater than the length of str1
The indexof parameter is string, looking for the first occurrence of the parameter string in the string and returning the position. such as String s= "0123DFDFDF"; int i=s.indexof ("df"); then i==4.
If you need a more powerful string parsing feature, you should use the Regex class to match the string with a regular expression.
indexof (): To position characters and strings in a string from the previous back; all return values are in absolute position of the string, such as NULL 1
Copy Code code as follows:
String test= "asdfjsdfjgkfasdsfsgfhgjgfjgdddd";
Test.indexof (' d ') = 2//front and back position D first occurrence
Test.indexof (' d ', 5,2) = 6//front-backward positioning D from the 5th position, check 2 digits, that is, from 5th to 7th;
LastIndexOf (): Locates characters and strings from behind in a string;
The usage is exactly the same as indexof ().
Here are IndexOfAny | | Lastindexofany
They accept the character array as the variable, and the other method, which returns the first subscript position of any character in the array.
As follows
Copy Code code as follows:
Char[] bbv={' s ', ' C ', ' B '};
String abc = "Acsdfgdfgchacscdsad";
Response.Write (ABC. IndexOfAny (BBV)) =1
Response.Write (ABC. IndexOfAny (BBV, 5)) =9
Response.Write (ABC. IndexOfAny (BBV, 5, 3)) =9
Lastindexofany ditto.
====================================================================
substring () usage
String A= "AADSFDJKFGKLFDGLFD"
A.substring (5)//intercept all strings from the fifth digit
A.substring (0,5)//intercept all strings from No. 0 to 5th