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:
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 number of indexes is string. Search for the first occurrence position of the number of indexes string in the string and return this position. For example, string S = "0123 dfdfdf"; int I = S. indexof ("DF"); then I = 4.
Assume that a more powerful string parsing function should be used in the RegEx class, and the regular expression is used to match the string.
Indexof (): locates the character and string from the front to the back in the string. All returned values are absolute positions of the string. If it is null, it is-1.
String test = "asdfjsdfjgkfasdsfsgfhgjgfjgdddd ";
Test. indexof ('D') = 2 // locate the location where D appears for the first time.
Test. indexof ('D', 1) = 2 // locate the first position where D appears from the third string
Test. indexof ('D', 5, 2) = 6 // locate D from the front to the back and start with 5th bits. query 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 character arrays as variable elements. The other methods are the same as above, and return the subscript location of any character in the array
For example:
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) // capture all strings from 5th
C # indexof usage