The complete reference of string amnipulating functions

capitalize(str)

Capitalizes a String changing the first letter to title case as per Character.toTitleCase(char).

center(str, int size)

Centers a String in a larger String of size size using the space character (' ').

center(str, int size, String padStr)

Centers a String in a larger String of size size.

chomp(str)

Removes one newline from end of a String if it's there, otherwise leave it alone.

chomp(str, String separator)

Removes separator from the end of str if it's there, otherwise leave it alone.

chop(str)

Remove the last character from a String.

boolean contains(str, String searchStr)

Checks if String contains a search String, handling null.

boolean containsIgnoreCase(str, String searchStr)

Checks if String contains a search String irrespective of case, handling null.

boolean containsNone(str, String invalidChars)

Checks that the String does not contain certain characters.

boolean containsOnly(str, String validChars)

Checks if the String contains only certain characters.

int countMatches(str, String sub)

Counts how many times the substring appears in the larger String.

deleteWhitespace(str)

Deletes all whitespaces from a String.

difference(str1, String str2)

Compares two Strings, and returns the portion where they differ.

boolean equals(str1, String str2)

Compares two Strings, returning true if they are equal.

boolean equalsIgnoreCase(str1, String str2)

Compares two Strings, returning true if they are equal ignoring the case.

int getLevenshteinDistance(s, String t)

Find the Levenshtein distance between two Strings.

int indexOf(str, String searchStr)

Finds the first index within a String, handling null.

int indexOf(str, String searchStr, int startPos)

Finds the first index within a String, handling null.

int indexOfAny(str, String searchChars)

Search a String to find the first index of any character in the given set of characters.

int indexOfAny(str, String[] searchStrs)

Find the first index of any of a set of potential substrings.

int indexOfAnyBut(str, String searchChars)

Search a String to find the first index of any character not in the given set of characters.

int indexOfDifference(str1, String str2)

Compares two Strings, and returns the index at which the Strings begin to differ.

boolean isAlpha(str)

Checks if the String contains only unicode letters.

boolean isAlphanumeric(str)

Checks if the String contains only unicode letters or digits.

boolean isAlphanumericSpace(str)

Checks if the String contains only unicode letters, digits or space (' ').

boolean isAlphaSpace(str)

Checks if the String contains only unicode letters and space (' ').

boolean isBlank(str)

Checks if a String is whitespace, empty ("") or null.

boolean isEmpty(str)

Checks if a String is empty ("") or null.

boolean isNotBlank(str)

Checks if a String is not empty (""), not null and not whitespace only.

boolean isNotEmpty(str)

Checks if a String is not empty ("") and not null.

boolean isNumeric(str)

Checks if the String contains only unicode digits.

boolean isNumericSpace(str)

Checks if the String contains only unicode digits or space (' ').

boolean isWhitespace(str)

Checks if the String contains only whitespace.

join(String[] array)

Joins the elements of the provided array into a single String containing the provided list of elements.

join(String[] array, String separator)

Joins the elements of the provided array into a single String containing the provided list of elements.

join(String[] array, String separator, int startIndex, int endIndex)

Joins the elements of the provided array into a single String containing the provided list of elements.

int lastIndexOf(str, String searchStr)

Finds the last index within a String, handling null.

int lastIndexOf(str, String searchStr, int startPos)

Finds the first index within a String, handling null.

int lastIndexOfAny(str, String[] searchStrs)

Find the latest index of any of a set of potential substrings.

left(str, int len)

Gets the leftmost len characters of a String.

leftPad(str, int size)

Left pad a String with spaces (' ').

leftPad(str, int size, String padStr)

Left pad a String with a specified String.

lowerCase(str)

Converts a String to lower case as per String.toLowerCase().

length(str)

This will return the no. of characters of the string.

mid(str, int pos, int len)

Gets len characters from the middle of a String.

int ordinalIndexOf(str, String searchStr, int ordinal)

Finds the n-th index within a String, handling null.

overlay(str, String overlay, int start, int end)

Overlays part of a String with another String.

remove(str, String remove)

Removes all occurances of a substring from within the source string.

removeEnd(str, String remove)

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

removeStart(str, String remove)

Removes a substring only if it is at the begining of a source string, otherwise returns the source string.

repeat(str, int repeat)

Repeat a String repeat times to form a new String.

replace(text, String repl, String with)

Replaces all occurrences of a String within another String.

replace(text, String repl, String with, int max)

Replaces a String with another String inside a larger String, for the first max values of the search String.

replaceChars(str, String searchChars, String replaceChars)

Replaces multiple characters in a String in one go.

replaceOnce(text, String repl, String with)

Replaces a String with another String inside a larger String, once.

reverse(str)

Reverses a String as per StringBuffer.reverse().

right(str, int len)

Gets the rightmost len characters of a String.

rightPad(str, int size)

Right pad a String with spaces (' ').

rightPad(str, int size, String padStr)

Right pad a String with a specified String.

String[] split(str)

Splits the provided text into an array, using whitespace as the separator.

String[] split(str, String separatorChars)

Splits the provided text into an array, separators specified.

String[] split(str, String separatorChars, int max)

Splits the provided text into an array with a maximum length, separators specified.

String[] splitByWholeSeparator(str, String separator)

Splits the provided text into an array, separator string specified.

String[] splitByWholeSeparator(str, String separator, int max)

Splits the provided text into an array, separator string specified.

String[] splitPreserveAllTokens(str)

Splits the provided text into an array, using whitespace as the separator, preserving all tokens, including empty tokens created by adjacent separators.

String[] splitPreserveAllTokens(str, String separatorChars)

Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

String[] splitPreserveAllTokens(str, String separatorChars, int max)

Splits the provided text into an array with a maximum length, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

strip(str)

Strips whitespace from the start and end of a String.

strip(str, String stripChars)

Strips any of a set of characters from the start and end of a String.

String[] stripAll(String[] strs)

Strips whitespace from the start and end of every String in an array.

String[] stripAll(String[] strs, String stripChars)

Strips any of a set of characters from the start and end of every String in an array.

stripEnd(str, String stripChars)

Strips any of a set of characters from the end of a String.

stripStart(str, String stripChars)

Strips any of a set of characters from the start of a String.

substring(str, int start)

Gets a substring from the specified String avoiding exceptions.

substring(str, int start, int end)

Gets a substring from the specified String avoiding exceptions.

substringAfter(str, String separator)

Gets the substring after the first occurrence of a separator.

substringAfterLast(str, String separator)

Gets the substring after the last occurrence of a separator.

substringBefore(str, String separator)

Gets the substring before the first occurrence of a separator.

substringBeforeLast(str, String separator)

Gets the substring before the last occurrence of a separator.

substringBetween(str, String tag)

Gets the String that is nested in between two instances of the same String.

substringBetween(str, String open, String close)

Gets the String that is nested in between two Strings.

String[] substringsBetween(str, String open, String close)

Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array.

swapCase(str)

Swaps the case of a String changing upper and title case to lower case, and lower case to upper case.

trim(str)

Removes control characters (char <= 32) from both ends of this String, handling null by returning null.

uncapitalize(str)

Uncapitalizes a String changing the first letter to title case.

upperCase(str)

Converts a String to upper case.

  • No labels