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 Summary
ConstructorDescriptionStringUtils
instances should NOT be constructed in standard programming. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
abbreviate
(String s, int maxWidth) static String
abbreviate
(String s, int offset, int maxWidth) static String
addAndDeHump
(String view) static String
capitalise
(String str) Capitalise a String.static String
capitaliseAllWords
(String str) Capitalise all the words in a String.static String
capitalizeFirstLetter
(String data) static String
Center a String in a larger String of sizen
.static String
Center a String in a larger String of sizen
.static String
Remove the last newline, and everything after it from a String.static String
Remove the last value of a supplied String, and everything after it from a String.static String
Remove a newline if and only if it is at the end of the supplied String.static String
Remove a value if and only if the String ends with that value.static String
Remove the last character from a String.static String
chopNewline
(String str) Remove\n
from end of a String if it's there.static String
Removes control characters, including whitespace, from both ends of this String, handlingnull
by returning an empty String.static String
concatenate
(Object[] array) Concatenates elements of an array into a single String.static boolean
Checks if String contains a search character, handlingnull
.static boolean
Checks if String contains a search String, handlingnull
.static int
countMatches
(String str, String sub) How many times is the substring in the larger String.static String
defaultString
(Object obj) Deprecated.static String
defaultString
(Object obj, String defaultString) Deprecated.static String
deleteWhitespace
(String str) Deletes all whitespaces from a String.static String
difference
(String s1, String s2) Compare two strings, and return the portion where they differ.static int
differenceAt
(String s1, String s2) Compare two strings, and return the index at which the strings begin to differ.static boolean
Deprecated.static boolean
equalsIgnoreCase
(String str1, String str2) Compares two Strings, returningtrue
if they are equal ignoring the case.static String
Escapes any values it finds into their String form.static String
static String
static String
Remove everything and return the last value of a supplied String, and everything after it from a String.static String
getNestedString
(String str, String tag) Get the String that is nested in between two instances of the same String.static String
getNestedString
(String str, String open, String close) Get the String that is nested in between two Strings.static String
getPrechomp
(String str, String sep) Remove and return everything before the first value of a supplied String from another String.static int
indexOfAny
(String str, String[] searchStrs) Find the first index of any of a set of potential substrings.static String
interpolate
(String text, Map<?, ?> namespace) static boolean
Checks if the String contains only unicode letters.static boolean
isAlphanumeric
(String str) Checks if the String contains only unicode letters or digits.static boolean
Checks if the String contains only unicode letters, digits or space (' '
).static boolean
isAlphaSpace
(String str) Checks if the String contains only unicode letters and space (' '
).static boolean
Checks if a String is whitespace, empty ("") or null.static boolean
Checks if a String isnull
or empty.static boolean
isNotBlank
(String str) Checks if a String is not empty (""), not null and not whitespace only.static boolean
isNotEmpty
(String str) Checks if a String is nonnull
and is not empty (length > 0
).static boolean
Checks if the String contains only unicode digits.static boolean
isNumericSpace
(String str) Checks if the String contains only unicode digits or space (' '
).static boolean
isWhitespace
(String str) Checks if the String contains only whitespace.static String
Joins the elements of the provided array into a single String containing the provided list of elements.static String
Joins the elements of the providedIterator
into a single String containing the provided elements.static int
lastIndexOfAny
(String str, String[] searchStrs) Find the latest index of any of a set of potential substrings.static String
Gets the leftmostn
characters of a String.static String
Left pad a String with spaces.static String
Left pad a String with a specified string.static String
Convert a String to lower case,null
String returnsnull
.static String
lowercaseFirstLetter
(String data) static String
Getsn
characters from the middle of a String.static String
overlayString
(String text, String overlay, int start, int end) Overlay a part of a String with another String.static String
Remove the first value of a supplied String, and everything before it from a String.static String
quoteAndEscape
(String source, char quoteChar) Quote and escape a String with the given character, handlingnull
.static String
quoteAndEscape
(String source, char quoteChar, char[] quotingTriggers) Quote and escape a String with the given character, handlingnull
.static String
quoteAndEscape
(String source, char quoteChar, char[] escapedChars, char[] quotingTriggers, char escapeChar, boolean force) static String
quoteAndEscape
(String source, char quoteChar, char[] escapedChars, char[] quotingTriggers, String escapePattern, boolean force) static String
quoteAndEscape
(String source, char quoteChar, char[] escapedChars, char escapeChar, boolean force) static String
removeAndHump
(String data, String replaceThis) static String
Remove all duplicate whitespace characters and line terminators are replaced with a single space.static String
Repeat a Stringn
times to form a new string.static String
Replace all occurrences of a char within another char.static String
Replace a char with another char inside a larger String, for the firstmax
values of the search char.static String
Replace all occurrences of a String within another String.static String
Replace a String with another String inside a larger String, for the firstmax
values of the search String.static String
replaceOnce
(String text, char repl, char with) Replace a char with another char inside a larger String, once.static String
replaceOnce
(String text, String repl, String with) Replace a String with another String inside a larger String, once.static String
Reverse a String.static String
reverseDelimitedString
(String str, String delimiter) Reverses a String that is delimited by a specific character.static String
Gets the rightmostn
characters of a String.static String
Right pad a String with spaces.static String
Right 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 String
Remove whitespace from the front and back of a String.static String
Remove 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 String
Strip any of a supplied String from the end of a String.static String
stripStart
(String str, String strip) Strip any of a supplied String from the start of a String.static String
Gets a substring from the specified string avoiding exceptions.static String
Gets a substring from the specified String avoiding exceptions.static String
Swaps the case of String.static String
Removes control characters, including whitespace, from both ends of this String, handlingnull
by returningnull
.static String
uncapitalise
(String str) Uncapitalise a String.static String
Uncapitalise all the words in a string.static String
Parses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.static String
unifyLineSeparators
(String s, String ls) Parses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.static String
Convert a String to upper case,null
String returnsnull
.
-
Constructor Details
-
StringUtils
public StringUtils()StringUtils
instances 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
-
clean
-
trim
-
deleteWhitespace
Deletes 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
-
isNotEmpty
Checks if a String is nonnull
and is not empty (length > 0
).- Parameters:
str
- the String to check- Returns:
- true if the String is non-null, and not length zero
-
isEmpty
Checks if a String isnull
or 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 returnstrue
for strings containing only whitespace characters.- Parameters:
str
- the String to check- Returns:
true
if the String isnull
, or length zero
-
isBlank
Checks 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:
true
if the String is null, empty or whitespace- Since:
- 1.5.2
-
isNotBlank
Checks 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:
true
if the String is not empty and not null and not whitespace- Since:
- 1.5.2
-
equals
Deprecated.Compares two Strings, returning
true
if they are equal.null
s are handled without exceptions. Twonull
references are considered to be equal. The comparison is case sensitive.- Parameters:
str1
- the first stringstr2
- the second string- Returns:
true
if the Strings are equal, case sensitive, or bothnull
- See Also:
-
equalsIgnoreCase
Compares two Strings, returning
true
if they are equal ignoring the case.Nulls
are handled without exceptions. Twonull
references are considered equal. Comparison is case insensitive.- Parameters:
str1
- the first stringstr2
- the second string- Returns:
true
if the Strings are equal, case insensitive, or bothnull
- See Also:
-
indexOfAny
Find the first index of any of a set of potential substrings.
null
String will return-1
.- Parameters:
str
- the String to checksearchStrs
- the Strings to search for- Returns:
- the first index of any of the searchStrs in str
- Throws:
NullPointerException
- if any of searchStrs[i] isnull
-
lastIndexOfAny
Find the latest index of any of a set of potential substrings.
null
string will return-1
.- Parameters:
str
- the String to checksearchStrs
- the Strings to search for- Returns:
- the last index of any of the Strings
- Throws:
NullPointerException
- if any of searchStrs[i] isnull
-
substring
Gets a substring from the specified string avoiding exceptions.
A negative start position can be used to start
n
characters from the end of the String.- Parameters:
str
- the String to get the substring fromstart
- the position to start from, negative means count back from the end of the String by this many characters- Returns:
- substring from start position
-
substring
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start/end
n
characters from the end of the String.- Parameters:
str
- the String to get the substring fromstart
- the position to start from, negative means count back from the end of the string by this many charactersend
- 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
-
left
Gets the leftmost
n
characters of a String.If
n
characters are not available, or the String isnull
, the String will be returned without an exception.- Parameters:
str
- the String to get the leftmost characters fromlen
- the length of the required String- Returns:
- the leftmost characters
- Throws:
IllegalArgumentException
- if len is less than zero
-
right
Gets the rightmost
n
characters of a String.If
n
characters are not available, or the String isnull
, the String will be returned without an exception.- Parameters:
str
- the String to get the rightmost characters fromlen
- the length of the required String- Returns:
- the leftmost characters
- Throws:
IllegalArgumentException
- if len is less than zero
-
mid
Gets
n
characters from the middle of a String.If
n
characters are not available, the remainder of the String will be returned without an exception. If the String isnull
,null
will be returned.- Parameters:
str
- the String to get the characters frompos
- the position to start fromlen
- the length of the required String- Returns:
- the leftmost characters
- Throws:
IndexOutOfBoundsException
- if pos is out of boundsIllegalArgumentException
- if len is less than zero
-
split
-
split
-
split
Splits 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
null
separator 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
StringTokenizer
does).- Parameters:
str
- The string to parse.separator
- Characters used as the delimiters. Ifnull
, 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
-
concatenate
-
join
Joins 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
null
separator is the same as a blank String.- Parameters:
array
- the array of values to join togetherseparator
- the separator character to use- Returns:
- the joined String
-
join
Joins the elements of the provided
Iterator
into a single String containing the provided elements.No delimiter is added before or after the list. A
null
separator is the same as a blank String.- Parameters:
iterator
- theIterator
of values to join togetherseparator
- the separator character to use- Returns:
- the joined String
-
replaceOnce
Replace a char with another char inside a larger String, once.
A
null
reference passed to this method is a no-op.- Parameters:
text
- text to search and replace inrepl
- char to search forwith
- char to replace with- Returns:
- the text with any replacements processed
- See Also:
-
replace
Replace all occurrences of a char within another char.
A
null
reference passed to this method is a no-op.- Parameters:
text
- text to search and replace inrepl
- char to search forwith
- char to replace with- Returns:
- the text with any replacements processed
- See Also:
-
replace
Replace a char with another char inside a larger String, for the first
max
values of the search char.A
null
reference passed to this method is a no-op.- Parameters:
text
- text to search and replace inrepl
- char to search forwith
- char to replace withmax
- maximum number of values to replace, or-1
if no maximum- Returns:
- the text with any replacements processed
-
replaceOnce
Replace a String with another String inside a larger String, once.
A
null
reference passed to this method is a no-op.- Parameters:
text
- text to search and replace inrepl
- String to search forwith
- String to replace with- Returns:
- the text with any replacements processed
- See Also:
-
replace
Replace all occurrences of a String within another String.
A
null
reference passed to this method is a no-op.- Parameters:
text
- text to search and replace inrepl
- String to search forwith
- String to replace with- Returns:
- the text with any replacements processed
- See Also:
-
replace
Replace a String with another String inside a larger String, for the first
max
values of the search String.A
null
reference passed to this method is a no-op.- Parameters:
text
- text to search and replace inrepl
- String to search forwith
- String to replace withmax
- maximum number of values to replace, or-1
if no maximum- Returns:
- the text with any replacements processed
-
overlayString
Overlay a part of a String with another String.
- Parameters:
text
- String to do overlaying inoverlay
- String to overlaystart
- int to start overlaying atend
- int to stop overlaying before- Returns:
- String with overlayed text
- Throws:
NullPointerException
- if text or overlay isnull
-
center
Center 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 centersize
- int size of new String- Returns:
- String containing centered String
- Throws:
NullPointerException
- if str isnull
-
center
Center 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 centersize
- int size of new Stringdelim
- String to buffer the new String with- Returns:
- String containing centered String
- Throws:
NullPointerException
- if str or delim isnull
ArithmeticException
- if delim is the empty String
-
chomp
Remove 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 isnull
-
chomp
Remove the last value of a supplied String, and everything after it from a String.
- Parameters:
str
- String to chomp fromsep
- String to chomp- Returns:
- String without chomped ending
- Throws:
NullPointerException
- if str or sep isnull
-
chompLast
Remove 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 isnull
-
chompLast
Remove a value if and only if the String ends with that value.
- Parameters:
str
- String to chomp fromsep
- String to chomp- Returns:
- String without chomped ending
- Throws:
NullPointerException
- if str or sep isnull
-
getChomp
Remove everything and return the last value of a supplied String, and everything after it from a String.
- Parameters:
str
- String to chomp fromsep
- String to chomp- Returns:
- String chomped
- Throws:
NullPointerException
- if str or sep isnull
-
prechomp
Remove the first value of a supplied String, and everything before it from a String.
- Parameters:
str
- String to chomp fromsep
- String to chomp- Returns:
- String without chomped beginning
- Throws:
NullPointerException
- if str or sep isnull
-
getPrechomp
Remove and return everything before the first value of a supplied String from another String.
- Parameters:
str
- String to chomp fromsep
- String to chomp- Returns:
- String prechomped
- Throws:
NullPointerException
- if str or sep isnull
-
chop
Remove 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 isnull
-
chopNewline
Remove
\n
from end of a String if it's there. If a\r
precedes it, then remove that too.- Parameters:
str
- String to chop a newline from- Returns:
- String without newline
- Throws:
NullPointerException
- if str isnull
-
escape
Escapes 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 isnull
-
repeat
Repeat a String
n
times to form a new string.- Parameters:
str
- String to repeatrepeat
- number of times to repeat str- Returns:
- String with repeated String
- Throws:
NegativeArraySizeException
- ifrepeat < 0
NullPointerException
- if str isnull
-
rightPad
Right pad a String with spaces.
The String is padded to the size of
n
.- Parameters:
str
- String to repeatsize
- number of times to repeat str- Returns:
- right padded String
- Throws:
NullPointerException
- if str isnull
-
rightPad
Right pad a String with a specified string.
The String is padded to the size of
n
.- Parameters:
str
- String to pad outsize
- size to pad todelim
- String to pad with- Returns:
- right padded String
- Throws:
NullPointerException
- if str or delim isnull
ArithmeticException
- if delim is the empty String
-
leftPad
Left pad a String with spaces.
The String is padded to the size of
n
.- Parameters:
str
- String to pad outsize
- size to pad to- Returns:
- left padded String
- Throws:
NullPointerException
- if str or delim isnull
-
leftPad
Left pad a String with a specified string. Pad to a size of n.- Parameters:
str
- String to pad outsize
- size to pad todelim
- String to pad with- Returns:
- left padded String
- Throws:
NullPointerException
- if str or delim is nullArithmeticException
- if delim is the empty string
-
strip
-
strip
Remove 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 fromdelim
- the String to remove at start and end- Returns:
- the stripped String
-
stripAll
-
stripAll
-
stripEnd
-
stripStart
-
upperCase
-
lowerCase
-
uncapitalise
-
capitalise
-
swapCase
-
capitaliseAllWords
Capitalise all the words in a String.
Uses
Character.isWhitespace(char)
as a separator between words.null
will returnnull
.- Parameters:
str
- the String to capitalise- Returns:
- capitalised String
-
uncapitaliseAllWords
Uncapitalise all the words in a string.
Uses
Character.isWhitespace(char)
as a separator between words.null
will returnnull
.- Parameters:
str
- the string to uncapitalise- Returns:
- uncapitalised string
-
getNestedString
Get the String that is nested in between two instances of the same String.
If
str
isnull
, will returnnull
.- Parameters:
str
- the String containing nested-stringtag
- the String before and after nested-string- Returns:
- the String that was nested, or
null
- Throws:
NullPointerException
- if tag isnull
-
getNestedString
Get the String that is nested in between two Strings.
- Parameters:
str
- the String containing nested-stringopen
- the String before nested-stringclose
- the String after nested-string- Returns:
- the String that was nested, or
null
- Throws:
NullPointerException
- if open or close isnull
-
countMatches
How many times is the substring in the larger String.
null
returns0
.- Parameters:
str
- the String to checksub
- the substring to count- Returns:
- the number of occurrences, 0 if the String is
null
- Throws:
NullPointerException
- if sub isnull
-
isAlpha
Checks if the String contains only unicode letters.
null
will returnfalse
. An empty String will returntrue
.- Parameters:
str
- the String to check- Returns:
true
if only contains letters, and is non-null
-
isWhitespace
Checks if the String contains only whitespace.
null
will returnfalse
. An empty String will returntrue
.- Parameters:
str
- the String to check- Returns:
true
if only contains whitespace, and is non-null
-
isAlphaSpace
Checks if the String contains only unicode letters and space (
' '
).null
will returnfalse
. An empty String will returntrue
.- Parameters:
str
- the String to check- Returns:
true
if only contains letters and space, and is non-null
-
isAlphanumeric
Checks if the String contains only unicode letters or digits.
null
will returnfalse
. An empty String will returntrue
.- Parameters:
str
- the String to check- Returns:
true
if only contains letters or digits, and is non-null
-
isAlphanumericSpace
Checks if the String contains only unicode letters, digits or space (
' '
).null
will returnfalse
. An empty String will returntrue
.- Parameters:
str
- the String to check- Returns:
true
if only contains letters, digits or space, and is non-null
-
isNumeric
Checks if the String contains only unicode digits.
null
will returnfalse
. An empty String will returntrue
.- Parameters:
str
- the String to check- Returns:
true
if only contains digits, and is non-null
-
isNumericSpace
Checks if the String contains only unicode digits or space (
' '
).null
will returnfalse
. An empty String will returntrue
.- Parameters:
str
- the String to check- Returns:
true
if only contains digits or space, and is non-null
-
defaultString
Deprecated.Returns either the passed in
Object
as a String, or, if theObject
isnull
, an empty String.- Parameters:
obj
- the Object to check- Returns:
- the passed in Object's toString, or blank if it was
null
- See Also:
-
defaultString
Deprecated.Returns either the passed in
Object
as a String, or, if theObject
isnull
, a passed in default String.- Parameters:
obj
- the Object to checkdefaultString
- the default String to return if str isnull
- Returns:
- the passed in string, or the default if it was
null
- See Also:
-
reverse
-
reverseDelimitedString
Reverses 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 reversedelimiter
- the delimiter to use- Returns:
- the reversed String
-
abbreviate
- Parameters:
s
- stringmaxWidth
- 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
- stringoffset
- left edge of source stringmaxWidth
- 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.
-
difference
Compare 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
- strings2
- string- Returns:
- the portion of s2 where it differs from s1; returns the empty string ("") if they are equal
-
differenceAt
-
interpolate
-
removeAndHump
-
capitalizeFirstLetter
-
lowercaseFirstLetter
-
addAndDeHump
-
quoteAndEscape
Quote 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 StringquoteChar
- the char used to quote- Returns:
- the String quoted and escaped
- Since:
- 1.5.1
- See Also:
-
quoteAndEscape
Quote and escape a String with the given character, handling
null
.- Parameters:
source
- the source StringquoteChar
- the char used to quotequotingTriggers
- chars generating a quote- Returns:
- the String quoted and escaped
- Since:
- 1.5.1
- See Also:
-
quoteAndEscape
public static String quoteAndEscape(String source, char quoteChar, char[] escapedChars, char escapeChar, boolean force) - Parameters:
source
- the source StringquoteChar
- the char used to quoteescapedChars
- chars to escapeescapeChar
- char used for escapingforce
- force the quoting- Returns:
- the String quoted and escaped
- Since:
- 1.5.1
- See Also:
-
quoteAndEscape
public static String quoteAndEscape(String source, char quoteChar, char[] escapedChars, char[] quotingTriggers, char escapeChar, boolean force) - Parameters:
source
- the source StringquoteChar
- the char used to quoteescapedChars
- chars to escapequotingTriggers
- chars generating a quoteescapeChar
- char used for escapingforce
- force the quoting- Returns:
- the String quoted and escaped
- Since:
- 1.5.1
-
quoteAndEscape
public static String quoteAndEscape(String source, char quoteChar, char[] escapedChars, char[] quotingTriggers, String escapePattern, boolean force) - Parameters:
source
- the source StringquoteChar
- the char used to quoteescapedChars
- chars to escapequotingTriggers
- chars generating a quoteescapePattern
- pattern used for escapingforce
- force the quoting- Returns:
- the String quoted and escaped
- Since:
- 3.0.4
-
escape
-
escape
-
removeDuplicateWhitespace
-
unifyLineSeparators
-
unifyLineSeparators
Parses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.- Parameters:
s
- a not null Stringls
- 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
-
contains
Checks if String contains a search character, handling
null
. This method usesString.indexOf(int)
.A
null
or 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 nullsearchChar
- the character to find- Returns:
- true if the String contains the search character, false if not or
null
string input - Since:
- 1.5.7
-
contains
Checks if String contains a search String, handling
null
. This method usesString.indexOf(int)
.A
null
String 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 nullsearchStr
- the String to find, may be null- Returns:
- true if the String contains the search String, false if not or
null
string input - Since:
- 1.5.7
-