IndexOf ()
Searches for the position of the specified character or string that appears for the first time in the string, and returns the first index value, for example:
Copy codeThe Code is as follows:
Str1.IndexOf ("word"); // search for the index value (location) of the word in str1)
Str1.IndexOf ("string"); // search for the index value (location) of the first character of "string" in str1)
Str1.IndexOf ("Word", start, end); // query end characters starting from start + 1 in str1, search for the position of "word" in STR1 [starting from the first character] Note: start + end cannot exceed the length of str1
The indexof parameter is string. Search for the position where the parameter string appears for the first time in the string and return the position. For example, string s = "0123 dfdfdf"; int I = s. indexof ("df"); then I = 4.
If you need more powerful string parsing functions, use the Regex class and use regular expressions to match strings.
Indexof (): Locates characters and strings from the front and back of a string. All returned values are absolute positions of the string. If it is null, the return value is-1.
Copy codeThe Code is as follows:
String test = "asdfjsdfjgkfasdsfsgfhgjgfjgdddd ";
Test. indexof ('D') = 2 // locate the location where d appears for the first time.
Test. indexof ('D', 5, 2) = 6 // locate d from the front to the back and query it from 5th bits. Check for 2 bits, that is, from 5th bits to 7th bits;
Lastindexof (): locates the character and string from the back and forward in the string;
The usage is exactly the same as that of indexof.
The following describes IndexOfAny | lastindexofany.
They accept the character array as the variable element. The other methods are the same as above, and return the subscript location of any character in the array.
As follows:
Copy codeThe Code is as follows:
Char [] bbv = {'s ', 'C',' B '};
String abc = "acsdfgdfgchacstcsad ";
Response. Write (abc. IndexOfAny (bbv) = 1
Response. Write (abc. IndexOfAny (bbv, 5) = 9
Response. Write (abc. IndexOfAny (bbv, 5, 3) = 9
Lastindexofany is the same as above.
========================================================== ======================================
Substring () Usage
String a = "aadsfdjkfgklfdglfd"
A. substring (5) // capture all strings after the fifth digit
A. substring (0th) // intercept all strings from 5th