Android Utililty Methods String Search

List of utility methods to do String Search

Description

The list of methods to do String Search are organized into topic(s).

Method

intsafeIndexOf(String s, String search)
safe Index Of
final int i = s.indexOf(search);
if (i == -1) {
    return s.length();
return i;
intindexOf(String str, String searchStr)
index Of
if (str == null || searchStr == null) {
    return -1;
return str.indexOf(searchStr);
intskipSpaces(String s, int start)
Skips any spaces at or after start and returns the index of first non-space character;
int limit = s.length();
int i = start;
for (; i < limit; i++) {
    if (s.charAt(i) != ' ') {
        break;
return i;
...
intnestedIndexOf(final String s, final int startPos, final String open, final String close)
nested Index Of
int depth = 0;
for (int i = startPos; i < s.length();) {
    if (s.startsWith(close, i)) {
        if (depth == 0) {
            return i;
        } else {
            --depth;
            i += close.length();
...
intfindFirstNotOf(String str, String chars)
find First Not Of
return findOf(str, chars, 0, (str.length() - 1), 1, false);
intfindFirstOf(String str, String chars)
find First Of
return findOf(str, chars, 0, (str.length() - 1), 1, true);
intfindLastNotOf(String str, String chars)
find Last Not Of
return findOf(str, chars, (str.length() - 1), 0, -1, false);
intfindLastOf(String str, String chars)
find Last Of
return findOf(str, chars, (str.length() - 1), 0, -1, true);
StringfirstCharUpper(String myString)
first Char Upper
if (myString != null && myString.length() > 1) {
    char[] stringArray = myString.toCharArray();
    stringArray[0] = Character.toUpperCase(stringArray[0]);
    myString = new String(stringArray);
return myString;
intlastIndexNotOf(String str, String chars, int fromIndex)
Finds the last index in str of a character not in the characters in 'chars' (similar to ANSI string.find_last_not_of).
fromIndex = Math.min(fromIndex, str.length() - 1);
for (int pos = fromIndex; pos >= 0; pos--) {
    if (chars.indexOf(str.charAt(pos)) < 0) {
        return pos;
return -1;