String.IndexOf method (Char, [startIndex], [count])
Reports the index of the first occurrence of the specified character in this instance. The search starts at the specified character position and checks the specified number of character positions.
Parameter
value
The Unicode character to look for. The search for value is case-sensitive.
startIndex (Int32)
Optional, search starting position. If not set, it starts from 0.
count (Int32)
Optional, the number of character positions to check.
Return value
If the character is found, it is the index position of value; otherwise, it is -1 if it is not found.
IndexOf()
Find the position where the specified character or string first appears in the string and return the index value, such as:
str1. IndexOf("Word"); //Find the index value (position) of "Word" in str1
str1.IndexOf("String"); //Find the first character of "String" Index value (position) in str1
str1.IndexOf("word",start,end); //Start from the start 1st character of str1, search for end characters, and find "word" in the character Position in string STR1 [from the first character] Note: start end cannot be greater than the length of str1
The indexof parameter is string, find the position where the parameter string first appears in the string and return the location. For example, string s="0123dfdfdf"; int i=s.indexof("df"); then i==4.
If you need more powerful string parsing function, you should use the Regex class and use regular expressions to match strings.
indexof(): Position characters and strings from front to back in the string; all return values refer to the absolute position in the string, if empty, it is - 1
string test= "asdfjsdfjgkfasdsfsgfhgjgfjgdddd";
test.indexof('d') =2 //Locate the first occurrence of d from front to back
test.indexof('d',1) = 2 //Locate d from front to back from the first occurrence of the third string
test.indexof('d',5,2) =6 //Locate d from front to back from the 5th position Start checking at digit, check 2 digits, that is, from the 5th to the 7th digit;
lastindexof(): Position characters and strings from back to front in a string;
usage Exactly the same as indexof().
The following introduces IndexOfAny ||lastindexofany
They accept character arrays as arguments. Other methods are the same as above, returning the earliest subscript position of any character in the array
is 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 Same as above.