Document directory
Int indexof (int ch, int fromindex) function: it is the first position of the character ch after the string fromindex bit.-1 is not found.
Indexof
public int indexOf(int ch)
-
Returns the index of the first occurrence of the specified character in this string. If
String
The value in the Character Sequence represented by the object is
ch
Returns the index that appears for the first time (expressed in Unicode code units ). For values between 0 and 0 xFFFF (including 0 and 0 xFFFF)
ch
Value. The returned value is
this.charAt(k) == ch
Minimum value of trueKValue. For otherch
Value. The returned value is
this.codePointAt(k) == ch
True minimumKValue. In either case, if this string does not contain such a character-1
.
-
-
-
Parameters:
-
ch
-One character (UNICODE code point ).
-
Return Value:
-
Index of the character for the first time in the Character Sequence represented by this object; if this character is not displayed, the return value is
-1
.
Indexof
public int indexOf(int ch, int fromIndex)
-
Returns the index that appears at the specified character for the first time in this string and starts searching from the specified index.
HereString
In the Character Sequence represented by an objectch
The character index of is not lessfromIndex
Returns the index with this value for the first time. For values between 0 and 0 xFFFF (including 0 and 0 xFFFF)ch
Value. The returned value is
(this.charAt(k) == ch) && (k >= fromIndex)
Minimum value of trueKValue. For otherch
Value. The returned value is
(this.codePointAt(k) == ch) && (k >= fromIndex)
Minimum value of trueKValue. In either case, iffromIndex
Otherwise, the system returns-1
.
fromIndex
There is no limit on the value. If it is negative, it returns the same effect as 0: the entire string is searched. If it is greater than the length of this string, it will have the same effect as it is equal to the length of this string:-1
.
All indexes are inchar
Value (UNICODE code unit ).
-
-
-
Parameters:
-
ch
-One character (UNICODE code point ).
-
fromIndex
-Start to search for the index.
-
Return Value:
-
The first occurrence of a character sequence in this object is greater than or equal
fromIndex
If this character is not displayed, the return value is
-1
.
Eg: String STR = "a2dfcfar1bzvb ";
System. Out. println (Str. indexof (97,2 ));
Let's look at this example. The output is 6.
If the ASCII value of A is 97, search for a from D and find the exact position of the string where output A is located. If no value is found, the output is-1! (The first position in Java starts from 0)
String. indexof function usage Summary
1. The indexof parameter is string, startindex: number;
The return value of indexof is int,
2. Function indexof contains the following formats:
1). strng. indexof (substring) // search for the substring in string. The default value starts from 0;
2). String. indexof (substring, int m) // search for the substring in string. The default value starts from the position M;
Public class hehe
{
Int I;
Int X;
String IP = NULL;
String input1 = NULL;
String input2 = NULL;
Public void main (string ARGs []) {
IP = "126.168.1.1 ";
I = IP. indexof ('.');
X = IP. indexof ('.', I + 1 );
Input1 = IP. substring (0, I );
Input2 = IP. substring (I + 1, x );
System. Out. println ("Input1 is "+ input1 );
System. Out. println ("The input2 is" + input2 );
}
}
The result is
TheInput1 is 126
The input2 is 168