/** * Searches the string builder to find the first reference to the specified char. * * @param ch the character to find * @return the first index of the character, or -1 if not found */ public int indexOf(char ch) { return indexOf(ch, 0); }
/** * Searches the string builder to find the first reference to the specified string. * <p> * Note that a null input string will return -1, whereas the JDK throws an exception. * * @param str the string to find, null returns -1 * @return the first index of the string, or -1 if not found */ public int indexOf(String str) { return indexOf(str, 0); }
/** * Checks if the string builder contains the specified string. * * @param str the string to find * @return true if the builder contains the string */ public boolean contains(String str) { return indexOf(str, 0) >= 0; }
/** * Searches the string builder using the matcher to find the first match. * <p> * Matchers can be used to perform advanced searching behaviour. * For example you could write a matcher to find the character 'a' * followed by a number. * * @param matcher the matcher to use, null returns -1 * @return the first index matched, or -1 if not found */ public int indexOf(StrMatcher matcher) { return indexOf(matcher, 0); }
/** * Checks if the string builder contains a string matched using the * specified matcher. * <p> * Matchers can be used to perform advanced searching behaviour. * For example you could write a matcher to search for the character * 'a' followed by a number. * * @param matcher the matcher to use, null returns -1 * @return true if the matcher finds a match in the builder */ public boolean contains(StrMatcher matcher) { return indexOf(matcher, 0) >= 0; }
/** * Deletes the string wherever it occurs in the builder. * * @param str the string to delete, null causes no action * @return this, to enable chaining */ public StrBuilder deleteAll(String str) { int len = (str == null ? 0 : str.length()); if (len > 0) { int index = indexOf(str, 0); while (index >= 0) { deleteImpl(index, index + len, len); index = indexOf(str, index); } } return this; }
/** * Replaces the search string with the replace string throughout the builder. * * @param searchStr the search string, null causes no action to occur * @param replaceStr the replace string, null is equivalent to an empty string * @return this, to enable chaining */ public StrBuilder replaceAll(String searchStr, String replaceStr) { int searchLen = (searchStr == null ? 0 : searchStr.length()); if (searchLen > 0) { int replaceLen = (replaceStr == null ? 0 : replaceStr.length()); int index = indexOf(searchStr, 0); while (index >= 0) { replaceImpl(index, index + searchLen, searchLen, replaceStr, replaceLen); index = indexOf(searchStr, index + replaceLen); } } return this; }
/** * Deletes the string wherever it occurs in the builder. * * @param str the string to delete, null causes no action * @return this, to enable chaining */ public StrBuilder deleteFirst(String str) { int len = (str == null ? 0 : str.length()); if (len > 0) { int index = indexOf(str, 0); if (index >= 0) { deleteImpl(index, index + len, len); } } return this; }
/** * Replaces the first instance of the search string with the replace string. * * @param searchStr the search string, null causes no action to occur * @param replaceStr the replace string, null is equivalent to an empty string * @return this, to enable chaining */ public StrBuilder replaceFirst(String searchStr, String replaceStr) { int searchLen = (searchStr == null ? 0 : searchStr.length()); if (searchLen > 0) { int index = indexOf(searchStr, 0); if (index >= 0) { int replaceLen = (replaceStr == null ? 0 : replaceStr.length()); replaceImpl(index, index + searchLen, searchLen, replaceStr, replaceLen); } } return this; }
return indexOf(str.charAt(0), startIndex);
/** * Searches the string builder to find the first reference to the specified char. * * @param ch the character to find * @return the first index of the character, or -1 if not found */ public int indexOf(char ch) { return indexOf(ch, 0); }
/** * Searches the string builder to find the first reference to the specified char. * * @param ch the character to find * @return the first index of the character, or -1 if not found */ public int indexOf(char ch) { return indexOf(ch, 0); }
/** * Checks if the string builder contains the specified string. * * @param str the string to find * @return true if the builder contains the string */ public boolean contains(String str) { return indexOf(str, 0) >= 0; }
/** * Searches the string builder to find the first reference to the specified string. * <p> * Note that a null input string will return -1, whereas the JDK throws an exception. * * @param str the string to find, null returns -1 * @return the first index of the string, or -1 if not found */ public int indexOf(String str) { return indexOf(str, 0); }
/** * Searches the string builder to find the first reference to the specified string. * <p> * Note that a null input string will return -1, whereas the JDK throws an exception. * * @param str the string to find, null returns -1 * @return the first index of the string, or -1 if not found */ public int indexOf(String str) { return indexOf(str, 0); }
/** * Checks if the string builder contains the specified string. * * @param str the string to find * @return true if the builder contains the string */ public boolean contains(String str) { return indexOf(str, 0) >= 0; }
/** * Searches the string builder to find the first reference to the specified char. * * @param ch the character to find * @return the first index of the character, or -1 if not found */ public int indexOf(char ch) { return indexOf(ch, 0); }
/** * Searches the string builder to find the first reference to the specified char. * * @param ch the character to find * @return the first index of the character, or -1 if not found */ public int indexOf(char ch) { return indexOf(ch, 0); }
/** * Checks if the string builder contains the specified string. * * @param str the string to find * @return true if the builder contains the string */ public boolean contains(String str) { return indexOf(str, 0) >= 0; }
/** * Searches the string builder to find the first reference to the specified string. * <p> * Note that a null input string will return -1, whereas the JDK throws an exception. * * @param str the string to find, null returns -1 * @return the first index of the string, or -1 if not found */ public int indexOf(String str) { return indexOf(str, 0); }