Class StringUtils
 Common String manipulation routines.
 
Originally from Turbine and the GenerationJavaCore library.
- Since:
- 1.0
- Author:
- Jon S. Stevens, Daniel Rall, Greg Coladonato, Henri Yandell, Ed Korthof, Rand McNeely, Stephen Colebourne, Fredrik Westermarck, Holger Krauth, Alexander Day Chaffee, Vincent Siveton
- 
Constructor SummaryConstructorsConstructorDescriptionStringUtilsinstances should NOT be constructed in standard programming.
- 
Method SummaryModifier and TypeMethodDescriptionstatic Stringabbreviate(String s, int maxWidth) static Stringabbreviate(String s, int offset, int maxWidth) static StringaddAndDeHump(String view) static Stringcapitalise(String str) Capitalise a String.static StringcapitaliseAllWords(String str) Capitalise all the words in a String.static StringcapitalizeFirstLetter(String data) static StringCenter a String in a larger String of sizen.static StringCenter a String in a larger String of sizen.static StringRemove the last newline, and everything after it from a String.static StringRemove the last value of a supplied String, and everything after it from a String.static StringRemove a newline if and only if it is at the end of the supplied String.static StringRemove a value if and only if the String ends with that value.static StringRemove the last character from a String.static StringchopNewline(String str) Remove\nfrom end of a String if it's there.static StringRemoves control characters, including whitespace, from both ends of this String, handlingnullby returning an empty String.static Stringconcatenate(Object[] array) Concatenates elements of an array into a single String.static booleanChecks if String contains a search character, handlingnull.static booleanChecks if String contains a search String, handlingnull.static intcountMatches(String str, String sub) How many times is the substring in the larger String.static StringdefaultString(Object obj) Deprecated.static StringdefaultString(Object obj, String defaultString) Deprecated.static StringdeleteWhitespace(String str) Deletes all whitespaces from a String.static Stringdifference(String s1, String s2) Compare two strings, and return the portion where they differ.static intdifferenceAt(String s1, String s2) Compare two strings, and return the index at which the strings begin to differ.static booleanDeprecated.static booleanequalsIgnoreCase(String str1, String str2) Compares two Strings, returningtrueif they are equal ignoring the case.static StringEscapes any values it finds into their String form.static Stringstatic Stringstatic StringRemove everything and return the last value of a supplied String, and everything after it from a String.static StringgetNestedString(String str, String tag) Get the String that is nested in between two instances of the same String.static StringgetNestedString(String str, String open, String close) Get the String that is nested in between two Strings.static StringgetPrechomp(String str, String sep) Remove and return everything before the first value of a supplied String from another String.static intindexOfAny(String str, String[] searchStrs) Find the first index of any of a set of potential substrings.static Stringinterpolate(String text, Map<?, ?> namespace) static booleanChecks if the String contains only unicode letters.static booleanisAlphanumeric(String str) Checks if the String contains only unicode letters or digits.static booleanChecks if the String contains only unicode letters, digits or space (' ').static booleanisAlphaSpace(String str) Checks if the String contains only unicode letters and space (' ').static booleanChecks if a String is whitespace, empty ("") or null.static booleanChecks if a String isnullor empty.static booleanisNotBlank(String str) Checks if a String is not empty (""), not null and not whitespace only.static booleanisNotEmpty(String str) Checks if a String is nonnulland is not empty (length > 0).static booleanChecks if the String contains only unicode digits.static booleanisNumericSpace(String str) Checks if the String contains only unicode digits or space (' ').static booleanisWhitespace(String str) Checks if the String contains only whitespace.static StringJoins the elements of the provided array into a single String containing the provided list of elements.static StringJoins the elements of the providedIteratorinto a single String containing the provided elements.static intlastIndexOfAny(String str, String[] searchStrs) Find the latest index of any of a set of potential substrings.static StringGets the leftmostncharacters of a String.static StringLeft pad a String with spaces.static StringLeft pad a String with a specified string.static StringConvert a String to lower case,nullString returnsnull.static StringlowercaseFirstLetter(String data) static StringGetsncharacters from the middle of a String.static StringoverlayString(String text, String overlay, int start, int end) Overlay a part of a String with another String.static StringRemove the first value of a supplied String, and everything before it from a String.static StringquoteAndEscape(String source, char quoteChar) Quote and escape a String with the given character, handlingnull.static StringquoteAndEscape(String source, char quoteChar, char[] quotingTriggers) Quote and escape a String with the given character, handlingnull.static StringquoteAndEscape(String source, char quoteChar, char[] escapedChars, char[] quotingTriggers, char escapeChar, boolean force) static StringquoteAndEscape(String source, char quoteChar, char[] escapedChars, char[] quotingTriggers, String escapePattern, boolean force) static StringquoteAndEscape(String source, char quoteChar, char[] escapedChars, char escapeChar, boolean force) static StringremoveAndHump(String data, String replaceThis) static StringRemove all duplicate whitespace characters and line terminators are replaced with a single space.static StringRepeat a Stringntimes to form a new string.static StringReplace all occurrences of a char within another char.static StringReplace a char with another char inside a larger String, for the firstmaxvalues of the search char.static StringReplace all occurrences of a String within another String.static StringReplace a String with another String inside a larger String, for the firstmaxvalues of the search String.static StringreplaceOnce(String text, char repl, char with) Replace a char with another char inside a larger String, once.static StringreplaceOnce(String text, String repl, String with) Replace a String with another String inside a larger String, once.static StringReverse a String.static StringreverseDelimitedString(String str, String delimiter) Reverses a String that is delimited by a specific character.static StringGets the rightmostncharacters of a String.static StringRight pad a String with spaces.static StringRight pad a String with a specified string.static String[]Splits the provided text into a array, using whitespace as the separator.static String[]static String[]Splits the provided text into a array, based on a given separator.static StringRemove whitespace from the front and back of a String.static StringRemove a specified String from the front and back of a String.static String[]Strip whitespace from the front and back of every String in the array.static String[]Strip the specified delimiter from the front and back of every String in the array.static StringStrip any of a supplied String from the end of a String.static StringstripStart(String str, String strip) Strip any of a supplied String from the start of a String.static StringGets a substring from the specified string avoiding exceptions.static StringGets a substring from the specified String avoiding exceptions.static StringSwaps the case of String.static StringRemoves control characters, including whitespace, from both ends of this String, handlingnullby returningnull.static Stringuncapitalise(String str) Uncapitalise a String.static StringUncapitalise all the words in a string.static StringParses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.static StringunifyLineSeparators(String s, String ls) Parses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.static StringConvert a String to upper case,nullString returnsnull.
- 
Constructor Details- 
StringUtilspublic StringUtils()StringUtilsinstances should NOT be constructed in standard programming. Instead, the class should be used asStringUtils.trim(" foo ");.This constructor is public to permit tools that require a JavaBean manager to operate. 
 
- 
- 
Method Details- 
cleanRemoves control characters, including whitespace, from both ends of this String, handling nullby returning an empty String.- Parameters:
- str- the String to check
- Returns:
- the trimmed text (never null)
- See Also:
 
- 
trimRemoves control characters, including whitespace, from both ends of this String, handling nullby returningnull.- Parameters:
- str- the String to check
- Returns:
- the trimmed text (or null)
- See Also:
 
- 
deleteWhitespaceDeletes all whitespaces from a String. Whitespace is defined by Character.isWhitespace(char).- Parameters:
- str- String target to delete whitespace from
- Returns:
- the String without whitespaces
 
- 
isNotEmptyChecks if a String is nonnulland is not empty (length > 0).- Parameters:
- str- the String to check
- Returns:
- true if the String is non-null, and not length zero
 
- 
isEmptyChecks if a String isnullor empty.Note: In releases prior 3.5.0, this method trimmed the input string such that it worked the same as isBlank(String). Since release 3.5.0 it no longer returnstruefor strings containing only whitespace characters.- Parameters:
- str- the String to check
- Returns:
- trueif the String is- null, or length zero
 
- 
isBlankChecks if a String is whitespace, empty ("") or null. StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false- Parameters:
- str- the String to check, may be null
- Returns:
- trueif the String is null, empty or whitespace
- Since:
- 1.5.2
 
- 
isNotBlankChecks if a String is not empty (""), not null and not whitespace only. StringUtils.isNotBlank(null) = false StringUtils.isNotBlank("") = false StringUtils.isNotBlank(" ") = false StringUtils.isNotBlank("bob") = true StringUtils.isNotBlank(" bob ") = true- Parameters:
- str- the String to check, may be null
- Returns:
- trueif the String is not empty and not null and not whitespace
- Since:
- 1.5.2
 
- 
equalsDeprecated.Compares two Strings, returning trueif they are equal.nulls are handled without exceptions. Twonullreferences are considered to be equal. The comparison is case sensitive.- Parameters:
- str1- the first string
- str2- the second string
- Returns:
- trueif the Strings are equal, case sensitive, or both- null
- See Also:
 
- 
equalsIgnoreCaseCompares two Strings, returning trueif they are equal ignoring the case.Nullsare handled without exceptions. Twonullreferences are considered equal. Comparison is case insensitive.- Parameters:
- str1- the first string
- str2- the second string
- Returns:
- trueif the Strings are equal, case insensitive, or both- null
- See Also:
 
- 
indexOfAnyFind the first index of any of a set of potential substrings. nullString will return-1.- Parameters:
- str- the String to check
- searchStrs- the Strings to search for
- Returns:
- the first index of any of the searchStrs in str
- Throws:
- NullPointerException- if any of searchStrs[i] is- null
 
- 
lastIndexOfAnyFind the latest index of any of a set of potential substrings. nullstring will return-1.- Parameters:
- str- the String to check
- searchStrs- the Strings to search for
- Returns:
- the last index of any of the Strings
- Throws:
- NullPointerException- if any of searchStrs[i] is- null
 
- 
substringGets a substring from the specified string avoiding exceptions. A negative start position can be used to start ncharacters from the end of the String.- Parameters:
- str- the String to get the substring from
- start- the position to start from, negative means count back from the end of the String by this many characters
- Returns:
- substring from start position
 
- 
substringGets a substring from the specified String avoiding exceptions. A negative start position can be used to start/end ncharacters from the end of the String.- Parameters:
- str- the String to get the substring from
- start- the position to start from, negative means count back from the end of the string by this many characters
- end- the position to end at (exclusive), negative means count back from the end of the String by this many characters
- Returns:
- substring from start position to end position
 
- 
leftGets the leftmost ncharacters of a String.If ncharacters are not available, or the String isnull, the String will be returned without an exception.- Parameters:
- str- the String to get the leftmost characters from
- len- the length of the required String
- Returns:
- the leftmost characters
- Throws:
- IllegalArgumentException- if len is less than zero
 
- 
rightGets the rightmost ncharacters of a String.If ncharacters are not available, or the String isnull, the String will be returned without an exception.- Parameters:
- str- the String to get the rightmost characters from
- len- the length of the required String
- Returns:
- the leftmost characters
- Throws:
- IllegalArgumentException- if len is less than zero
 
- 
midGets ncharacters from the middle of a String.If ncharacters are not available, the remainder of the String will be returned without an exception. If the String isnull,nullwill be returned.- Parameters:
- str- the String to get the characters from
- pos- the position to start from
- len- the length of the required String
- Returns:
- the leftmost characters
- Throws:
- IndexOutOfBoundsException- if pos is out of bounds
- IllegalArgumentException- if len is less than zero
 
- 
splitSplits the provided text into a array, using whitespace as the separator. The separator is not included in the returned String array. - Parameters:
- str- the String to parse
- Returns:
- an array of parsed Strings
 
- 
split- Parameters:
- text- The string to parse.
- separator- Characters used as the delimiters. If- null, splits on whitespace.
- Returns:
- an array of parsed Strings
 
- 
splitSplits the provided text into a array, based on a given separator. The separator is not included in the returned String array. The maximum number of splits to perform can be controlled. A nullseparator will cause parsing to be on whitespace.This is useful for quickly splitting a String directly into an array of tokens, instead of an enumeration of tokens (as StringTokenizerdoes).- Parameters:
- str- The string to parse.
- separator- Characters used as the delimiters. If- null, splits on whitespace.
- max- The maximum number of elements to include in the array. A zero or negative value implies no limit.
- Returns:
- an array of parsed Strings
 
- 
concatenateConcatenates elements of an array into a single String. The difference from join is that concatenate has no delimiter. - Parameters:
- array- the array of values to concatenate.
- Returns:
- the concatenated string.
 
- 
joinJoins the elements of the provided array into a single String containing the provided list of elements. No delimiter is added before or after the list. A nullseparator is the same as a blank String.- Parameters:
- array- the array of values to join together
- separator- the separator character to use
- Returns:
- the joined String
 
- 
joinJoins the elements of the provided Iteratorinto a single String containing the provided elements.No delimiter is added before or after the list. A nullseparator is the same as a blank String.- Parameters:
- iterator- the- Iteratorof values to join together
- separator- the separator character to use
- Returns:
- the joined String
 
- 
replaceOnceReplace a char with another char inside a larger String, once. A nullreference passed to this method is a no-op.- Parameters:
- text- text to search and replace in
- repl- char to search for
- with- char to replace with
- Returns:
- the text with any replacements processed
- See Also:
 
- 
replaceReplace all occurrences of a char within another char. A nullreference passed to this method is a no-op.- Parameters:
- text- text to search and replace in
- repl- char to search for
- with- char to replace with
- Returns:
- the text with any replacements processed
- See Also:
 
- 
replaceReplace a char with another char inside a larger String, for the first maxvalues of the search char.A nullreference passed to this method is a no-op.- Parameters:
- text- text to search and replace in
- repl- char to search for
- with- char to replace with
- max- maximum number of values to replace, or- -1if no maximum
- Returns:
- the text with any replacements processed
 
- 
replaceOnceReplace a String with another String inside a larger String, once. A nullreference passed to this method is a no-op.- Parameters:
- text- text to search and replace in
- repl- String to search for
- with- String to replace with
- Returns:
- the text with any replacements processed
- See Also:
 
- 
replaceReplace all occurrences of a String within another String. A nullreference passed to this method is a no-op.- Parameters:
- text- text to search and replace in
- repl- String to search for
- with- String to replace with
- Returns:
- the text with any replacements processed
- See Also:
 
- 
replaceReplace a String with another String inside a larger String, for the first maxvalues of the search String.A nullreference passed to this method is a no-op.- Parameters:
- text- text to search and replace in
- repl- String to search for
- with- String to replace with
- max- maximum number of values to replace, or- -1if no maximum
- Returns:
- the text with any replacements processed
 
- 
overlayStringOverlay a part of a String with another String. - Parameters:
- text- String to do overlaying in
- overlay- String to overlay
- start- int to start overlaying at
- end- int to stop overlaying before
- Returns:
- String with overlayed text
- Throws:
- NullPointerException- if text or overlay is- null
 
- 
centerCenter a String in a larger String of size n.Uses spaces as the value to buffer the String with. Equivalent to center(str, size, " ").- Parameters:
- str- String to center
- size- int size of new String
- Returns:
- String containing centered String
- Throws:
- NullPointerException- if str is- null
 
- 
centerCenter a String in a larger String of size n.Uses a supplied String as the value to buffer the String with. - Parameters:
- str- String to center
- size- int size of new String
- delim- String to buffer the new String with
- Returns:
- String containing centered String
- Throws:
- NullPointerException- if str or delim is- null
- ArithmeticException- if delim is the empty String
 
- 
chompRemove the last newline, and everything after it from a String. - Parameters:
- str- String to chomp the newline from
- Returns:
- String without chomped newline
- Throws:
- NullPointerException- if str is- null
 
- 
chompRemove the last value of a supplied String, and everything after it from a String. - Parameters:
- str- String to chomp from
- sep- String to chomp
- Returns:
- String without chomped ending
- Throws:
- NullPointerException- if str or sep is- null
 
- 
chompLastRemove a newline if and only if it is at the end of the supplied String. - Parameters:
- str- String to chomp from
- Returns:
- String without chomped ending
- Throws:
- NullPointerException- if str is- null
 
- 
chompLastRemove a value if and only if the String ends with that value. - Parameters:
- str- String to chomp from
- sep- String to chomp
- Returns:
- String without chomped ending
- Throws:
- NullPointerException- if str or sep is- null
 
- 
getChompRemove everything and return the last value of a supplied String, and everything after it from a String. - Parameters:
- str- String to chomp from
- sep- String to chomp
- Returns:
- String chomped
- Throws:
- NullPointerException- if str or sep is- null
 
- 
prechompRemove the first value of a supplied String, and everything before it from a String. - Parameters:
- str- String to chomp from
- sep- String to chomp
- Returns:
- String without chomped beginning
- Throws:
- NullPointerException- if str or sep is- null
 
- 
getPrechompRemove and return everything before the first value of a supplied String from another String. - Parameters:
- str- String to chomp from
- sep- String to chomp
- Returns:
- String prechomped
- Throws:
- NullPointerException- if str or sep is- null
 
- 
chopRemove the last character from a String. If the String ends in \r\n, then remove both of them.- Parameters:
- str- String to chop last character from
- Returns:
- String without last character
- Throws:
- NullPointerException- if str is- null
 
- 
chopNewlineRemove \nfrom end of a String if it's there. If a\rprecedes it, then remove that too.- Parameters:
- str- String to chop a newline from
- Returns:
- String without newline
- Throws:
- NullPointerException- if str is- null
 
- 
escapeEscapes any values it finds into their String form. So a tab becomes the characters '\\'and't'.- Parameters:
- str- String to escape values in
- Returns:
- String with escaped values
- Throws:
- NullPointerException- if str is- null
 
- 
repeatRepeat a String ntimes to form a new string.- Parameters:
- str- String to repeat
- repeat- number of times to repeat str
- Returns:
- String with repeated String
- Throws:
- NegativeArraySizeException- if- repeat < 0
- NullPointerException- if str is- null
 
- 
rightPadRight pad a String with spaces. The String is padded to the size of n.- Parameters:
- str- String to repeat
- size- number of times to repeat str
- Returns:
- right padded String
- Throws:
- NullPointerException- if str is- null
 
- 
rightPadRight pad a String with a specified string. The String is padded to the size of n.- Parameters:
- str- String to pad out
- size- size to pad to
- delim- String to pad with
- Returns:
- right padded String
- Throws:
- NullPointerException- if str or delim is- null
- ArithmeticException- if delim is the empty String
 
- 
leftPadLeft pad a String with spaces. The String is padded to the size of n.- Parameters:
- str- String to pad out
- size- size to pad to
- Returns:
- left padded String
- Throws:
- NullPointerException- if str or delim is- null
 
- 
leftPadLeft pad a String with a specified string. Pad to a size of n.- Parameters:
- str- String to pad out
- size- size to pad to
- delim- String to pad with
- Returns:
- left padded String
- Throws:
- NullPointerException- if str or delim is null
- ArithmeticException- if delim is the empty string
 
- 
stripRemove whitespace from the front and back of a String. - Parameters:
- str- the String to remove whitespace from
- Returns:
- the stripped String
 
- 
stripRemove a specified String from the front and back of a String. If whitespace is wanted to be removed, used the strip(java.lang.String)method.- Parameters:
- str- the String to remove a string from
- delim- the String to remove at start and end
- Returns:
- the stripped String
 
- 
stripAllStrip whitespace from the front and back of every String in the array. - Parameters:
- strs- the Strings to remove whitespace from
- Returns:
- the stripped Strings
 
- 
stripAllStrip the specified delimiter from the front and back of every String in the array. - Parameters:
- strs- the Strings to remove a String from
- delimiter- the String to remove at start and end
- Returns:
- the stripped Strings
 
- 
stripEndStrip any of a supplied String from the end of a String. If the strip String is null, whitespace is stripped.- Parameters:
- str- the String to remove characters from
- strip- the String to remove
- Returns:
- the stripped String
 
- 
stripStartStrip any of a supplied String from the start of a String. If the strip String is null, whitespace is stripped.- Parameters:
- str- the String to remove characters from
- strip- the String to remove
- Returns:
- the stripped String
 
- 
upperCaseConvert a String to upper case, nullString returnsnull.- Parameters:
- str- the String to uppercase
- Returns:
- the upper cased String
 
- 
lowerCaseConvert a String to lower case, nullString returnsnull.- Parameters:
- str- the string to lowercase
- Returns:
- the lower cased String
 
- 
uncapitaliseUncapitalise a String. That is, convert the first character into lower-case. nullis returned asnull.- Parameters:
- str- the String to uncapitalise
- Returns:
- uncapitalised String
 
- 
capitaliseCapitalise a String. That is, convert the first character into title-case. nullis returned asnull.- Parameters:
- str- the String to capitalise
- Returns:
- capitalised String
 
- 
swapCaseSwaps the case of String. Properly looks after making sure the start of words are Titlecase and not Uppercase. nullis returned asnull.- Parameters:
- str- the String to swap the case of
- Returns:
- the modified String
 
- 
capitaliseAllWordsCapitalise all the words in a String. Uses Character.isWhitespace(char)as a separator between words.nullwill returnnull.- Parameters:
- str- the String to capitalise
- Returns:
- capitalised String
 
- 
uncapitaliseAllWordsUncapitalise all the words in a string. Uses Character.isWhitespace(char)as a separator between words.nullwill returnnull.- Parameters:
- str- the string to uncapitalise
- Returns:
- uncapitalised string
 
- 
getNestedStringGet the String that is nested in between two instances of the same String. If strisnull, will returnnull.- Parameters:
- str- the String containing nested-string
- tag- the String before and after nested-string
- Returns:
- the String that was nested, or null
- Throws:
- NullPointerException- if tag is- null
 
- 
getNestedStringGet the String that is nested in between two Strings. - Parameters:
- str- the String containing nested-string
- open- the String before nested-string
- close- the String after nested-string
- Returns:
- the String that was nested, or null
- Throws:
- NullPointerException- if open or close is- null
 
- 
countMatchesHow many times is the substring in the larger String. nullreturns0.- Parameters:
- str- the String to check
- sub- the substring to count
- Returns:
- the number of occurrences, 0 if the String is null
- Throws:
- NullPointerException- if sub is- null
 
- 
isAlphaChecks if the String contains only unicode letters. nullwill returnfalse. An empty String will returntrue.- Parameters:
- str- the String to check
- Returns:
- trueif only contains letters, and is non-null
 
- 
isWhitespaceChecks if the String contains only whitespace. nullwill returnfalse. An empty String will returntrue.- Parameters:
- str- the String to check
- Returns:
- trueif only contains whitespace, and is non-null
 
- 
isAlphaSpaceChecks if the String contains only unicode letters and space ( ' ').nullwill returnfalse. An empty String will returntrue.- Parameters:
- str- the String to check
- Returns:
- trueif only contains letters and space, and is non-null
 
- 
isAlphanumericChecks if the String contains only unicode letters or digits. nullwill returnfalse. An empty String will returntrue.- Parameters:
- str- the String to check
- Returns:
- trueif only contains letters or digits, and is non-null
 
- 
isAlphanumericSpaceChecks if the String contains only unicode letters, digits or space ( ' ').nullwill returnfalse. An empty String will returntrue.- Parameters:
- str- the String to check
- Returns:
- trueif only contains letters, digits or space, and is non-null
 
- 
isNumericChecks if the String contains only unicode digits. nullwill returnfalse. An empty String will returntrue.- Parameters:
- str- the String to check
- Returns:
- trueif only contains digits, and is non-null
 
- 
isNumericSpaceChecks if the String contains only unicode digits or space ( ' ').nullwill returnfalse. An empty String will returntrue.- Parameters:
- str- the String to check
- Returns:
- trueif only contains digits or space, and is non-null
 
- 
defaultStringDeprecated.Returns either the passed in Objectas a String, or, if theObjectisnull, an empty String.- Parameters:
- obj- the Object to check
- Returns:
- the passed in Object's toString, or blank if it was null
- See Also:
 
- 
defaultStringDeprecated.Returns either the passed in Objectas a String, or, if theObjectisnull, a passed in default String.- Parameters:
- obj- the Object to check
- defaultString- the default String to return if str is- null
- Returns:
- the passed in string, or the default if it was null
- See Also:
 
- 
reverseReverse a String. nullString returnsnull.- Parameters:
- str- the String to reverse
- Returns:
- the reversed String
 
- 
reverseDelimitedStringReverses a String that is delimited by a specific character. The Strings between the delimiters are not reversed. Thus java.lang.String becomes String.lang.java (if the delimiter is '.').- Parameters:
- str- the String to reverse
- delimiter- the delimiter to use
- Returns:
- the reversed String
 
- 
abbreviate- Parameters:
- s- string
- maxWidth- maximum length of result string
- Returns:
- Turn "Now is the time for all good men" into "Now is the time for..."
 Specifically: If str is less than max characters long, return it. Else abbreviate it to (substring(str, 0, max-3) + "..."). If maxWidth is less than 3, throw an IllegalArgumentException. In no case will it return a string of length greater than maxWidth. 
 
- 
abbreviate- Parameters:
- s- string
- offset- left edge of source string
- maxWidth- maximum length of result string
- Returns:
- Turn "Now is the time for all good men" into "...is the time for..." Works like abbreviate(String, int), but allows you to specify a "left edge" offset. Note that this left edge is not necessarily going to be the leftmost character in the result, or the first character following the ellipses, but it will appear somewhere in the result. In no case will it return a string of length greater than maxWidth.
 
- 
differenceCompare two strings, and return the portion where they differ. (More precisely, return the remainder of the second string, starting from where it's different from the first.)E.g. strdiff("i am a machine", "i am a robot") -> "robot" - Parameters:
- s1- string
- s2- string
- Returns:
- the portion of s2 where it differs from s1; returns the empty string ("") if they are equal
 
- 
differenceAtCompare two strings, and return the index at which the strings begin to differ.E.g. strdiff("i am a machine", "i am a robot") -> 7 - Parameters:
- s1- string
- s2- string
- Returns:
- the index where s2 and s1 begin to differ; -1 if they are equal
 
- 
interpolate
- 
removeAndHump
- 
capitalizeFirstLetter
- 
lowercaseFirstLetter
- 
addAndDeHump
- 
quoteAndEscapeQuote and escape a String with the given character, handling null.StringUtils.quoteAndEscape(null, *) = null StringUtils.quoteAndEscape("", *) = "" StringUtils.quoteAndEscape("abc", '"') = abc StringUtils.quoteAndEscape("a\"bc", '"') = "a\"bc" StringUtils.quoteAndEscape("a\"bc", '\'') = 'a\"bc'- Parameters:
- source- the source String
- quoteChar- the char used to quote
- Returns:
- the String quoted and escaped
- Since:
- 1.5.1
- See Also:
 
- 
quoteAndEscapeQuote and escape a String with the given character, handling null.- Parameters:
- source- the source String
- quoteChar- the char used to quote
- quotingTriggers- chars generating a quote
- Returns:
- the String quoted and escaped
- Since:
- 1.5.1
- See Also:
 
- 
quoteAndEscapepublic static String quoteAndEscape(String source, char quoteChar, char[] escapedChars, char escapeChar, boolean force) - Parameters:
- source- the source String
- quoteChar- the char used to quote
- escapedChars- chars to escape
- escapeChar- char used for escaping
- force- force the quoting
- Returns:
- the String quoted and escaped
- Since:
- 1.5.1
- See Also:
 
- 
quoteAndEscapepublic static String quoteAndEscape(String source, char quoteChar, char[] escapedChars, char[] quotingTriggers, char escapeChar, boolean force) - Parameters:
- source- the source String
- quoteChar- the char used to quote
- escapedChars- chars to escape
- quotingTriggers- chars generating a quote
- escapeChar- char used for escaping
- force- force the quoting
- Returns:
- the String quoted and escaped
- Since:
- 1.5.1
 
- 
quoteAndEscapepublic static String quoteAndEscape(String source, char quoteChar, char[] escapedChars, char[] quotingTriggers, String escapePattern, boolean force) - Parameters:
- source- the source String
- quoteChar- the char used to quote
- escapedChars- chars to escape
- quotingTriggers- chars generating a quote
- escapePattern- pattern used for escaping
- force- force the quoting
- Returns:
- the String quoted and escaped
- Since:
- 3.0.4
 
- 
escape- Parameters:
- source- the source String
- escapedChars- chars to escape
- escapeChar- char used for escaping
- Returns:
- the String escaped
- Since:
- 1.5.1
 
- 
escape- Parameters:
- source- the source String
- escapedChars- chars to escape
- escapePattern- pattern used for escaping
- Returns:
- the String escaped
- Since:
- 3.0.4
 
- 
removeDuplicateWhitespaceRemove all duplicate whitespace characters and line terminators are replaced with a single space.- Parameters:
- s- a not null String
- Returns:
- a string with unique whitespace.
- Since:
- 1.5.7
 
- 
unifyLineSeparatorsParses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.- Parameters:
- s- a not null String
- Returns:
- a String that contains only System line separators.
- Since:
- 1.5.7
- See Also:
 
- 
unifyLineSeparatorsParses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.- Parameters:
- s- a not null String
- ls- the wanted line separator ("\n" on UNIX), if null using the System line separator.
- Returns:
- a String that contains only System line separators.
- Throws:
- IllegalArgumentException- if ls is not '\n', '\r' and '\r\n' characters.
- Since:
- 1.5.7
 
- 
containsChecks if String contains a search character, handling null. This method usesString.indexOf(int).A nullor empty ("") String will returnfalse.StringUtils.contains(null, *) = false StringUtils.contains("", *) = false StringUtils.contains("abc", 'a') = true StringUtils.contains("abc", 'z') = false- Parameters:
- str- the String to check, may be null
- searchChar- the character to find
- Returns:
- true if the String contains the search character, false if not or nullstring input
- Since:
- 1.5.7
 
- 
containsChecks if String contains a search String, handling null. This method usesString.indexOf(int).A nullString will returnfalse.StringUtils.contains(null, *) = false StringUtils.contains(*, null) = false StringUtils.contains("", "") = true StringUtils.contains("abc", "") = true StringUtils.contains("abc", "a") = true StringUtils.contains("abc", "z") = false- Parameters:
- str- the String to check, may be null
- searchStr- the String to find, may be null
- Returns:
- true if the String contains the search String, false if not or nullstring input
- Since:
- 1.5.7
 
 
-