Finds the first occurrence of a specified character or string in a string, and returns the index value, such as:
Str1. IndexOf ("word");//Find the index value (position) of "word" in str1 str1. IndexOf ("string");//Find the index value (position) str1 of the first character of the string in str1. IndexOf ("word", start,end);//from str1 start+1 characters, look for end characters, find the position of "word" in string STR1 [from the first character] Note: Start+end cannot be greater than str1 length
The indexof parameter is string, looking for the position of the first occurrence of the argument string in the string and returning the position. such as String s= "0123DFDFDF"; int i=s.indexof ("df"), then i==4. Returns 1 if it is not found.
If you need more powerful string parsing, you should use a Regex class to match strings with regular expressions.
IndexOf (): Position characters and strings from the front to back in a string; all return values refer to the absolute position of the string, or 1 if null.
String test= "asdfjsdfjgkfasdsfsgfhgjgfjgdddd"; Test.indexof (' d ') =2 //front-to-back position D first occurrence test.indexof (' d ', 5,2) =6 //front-to-back positioning D starting from the 5th position, check 2, that is, from 5th to 7th;
LastIndexOf (): Positions characters and strings in a string from the back forward;
Usage is exactly the same as indexof ().
The following introduction IndexOfAny | | Lastindexofany
They accept the character array as a variable, as in the other way, returning any one of the characters in the array to the first occurrence of the subscript position
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 Ibid.
SUBSTRING () Usage
String A= "AADSFDJKFGKLFDGLFD"
A.substring (5)//intercept all strings after the fifth bit
A.substring (0,5)//intercept all strings from No. 0 to 5th
The above is the C # Index of the usage (reprint) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!