public static interface StringUtil.IndexOf
indexOf(CharSequence, int, int)| Modifier and Type | Method and Description |
|---|---|
int |
indexOf(CharSequence haystack)
The equivalent of
String.indexOf(String). |
int |
indexOf(CharSequence haystack,
int minIndex)
The equivalent of
String.indexOf(String, int). |
int |
indexOf(CharSequence haystack,
int minIndex,
int maxIndex)
Like
indexOf(CharSequence, int), but the match terminates at index maxIndex (inclusive). |
int |
indexOf(CharSequence haystack,
int minIndex,
int maxIndex,
int limit)
Like
indexOf(CharSequence, int, int), but never accesses haystack chars at position
limit or greater. |
int |
lastIndexOf(CharSequence haystack)
The equivalent of
String.lastIndexOf(String). |
int |
lastIndexOf(CharSequence haystack,
int maxIndex)
The equivalent of
String.lastIndexOf(String, int). |
int |
lastIndexOf(CharSequence haystack,
int minIndex,
int maxIndex)
Like
lastIndexOf(CharSequence, int), but the match terminates at index minIndex
(inclusive). |
String |
toString() |
int indexOf(CharSequence haystack)
String.indexOf(String).
For the return value, the following condition holds true:
StringUtil.newIndexOf(needle).indexOf(haystack) == haystack.indexOf(needle)
0 ... haystack.length() - needle.length(), or -1int indexOf(CharSequence haystack, int minIndex)
String.indexOf(String, int).
For the return value, the following condition holds true:
StringUtil.newIndexOf(needle).indexOf(haystack, minIndex) == haystack.indexOf(needle, minIndex)
max(0, minIndex) ... haystack.length() - needle.length(), or -1int indexOf(CharSequence haystack, int minIndex, int maxIndex)
indexOf(CharSequence, int), but the match terminates at index maxIndex (inclusive).max(0, minIndex) ... min(maxIndex, haystack.length() - needle.length()), or -1int indexOf(CharSequence haystack, int minIndex, int maxIndex, int limit)
indexOf(CharSequence, int, int), but never accesses haystack chars at position
limit or greater.
Instead, if there are partial matches at positions limit -
needle.length - 1 ... limit - 1, then the first of these is
returned.
Examples:
| needle | haystack | minIndex | maxIndex | limit | result |
|---|---|---|---|---|---|
ABCDE | _ABCDE_** | <=1 | >=1 | 7 | 1 |
ABCDE | __ABCDE** | <=2 | >=2 | 7 | 2 |
ABCDE | ___ABCD** | <=3 | >=3 | 7 | 3 |
ABCDE | ____ABC** | <=4 | >=4 | 7 | 4 |
ABCDE | _____AB** | <=5 | >=5 | 7 | 5 |
ABCDE | ______A** | <=6 | >=6 | 7 | 6 |
ABCDE | _______** | <=7 | >=7 | 7 | 7 |
("_": Any character but "ABCDE"; "*": Any character.)
limit - 0...haystack.lengthint lastIndexOf(CharSequence haystack)
String.lastIndexOf(String).
For the return value, the following condition holds true:
StringUtil.newIndexOf(needle).lastIndexOf(haystack) == haystack.lastIndexOf(needle)
0 ... haystack.length() - needle.length(), or -1int lastIndexOf(CharSequence haystack, int maxIndex)
String.lastIndexOf(String, int).
For the return value, the following condition holds true:
StringUtil.newIndexOf(needle).lastIndexOf(haystack, maxIndex) == haystack.lastIndexOf(needle, maxIndex)
0 ... min(maxIndex, haystack.length() - needle.length()), or -1int lastIndexOf(CharSequence haystack, int minIndex, int maxIndex)
lastIndexOf(CharSequence, int), but the match terminates at index minIndex
(inclusive).max(0, minIndex) ... min(maxIndex, haystack.length() - needle.length()), or -1Copyright © 2018 Arno Unkrig. All rights reserved.