public class StringUtils
extends Object
Utilities for handling strings
| Modifiers | Name | Description |
|---|---|---|
static int |
DOLLAR_SLASHY |
Slashy kind for a $/.../$ string. |
static int |
NONE_SLASHY |
Slashy kind for an ordinary string. |
static int |
SLASHY |
Slashy kind for a /.../ string. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static long |
countChar(String text, char c)Counts how many UTF-16 code units in text equal c. |
|
public static boolean |
isEmpty(CharSequence cs)Copied from Apache commons-lang3-3.6 |
|
public static boolean |
matches(String text, Pattern pattern)Reports whether the whole of text matches pattern. |
|
public static String |
removeCR(String text)Replaces every \r\n in text with \n. |
|
public static String |
replace(String text, String searchString, String replacement)The modified implementation is based on StringUtils#replace(String text, String searchString, String replacement, int max), Apache commons-lang3-3.6 |
|
public static String |
replaceEscapes(String text, int slashyType)Rewrites escapes in text according to slashyType.
|
|
public static String |
replaceHexEscapes(String text)Replaces each \uXXXX whose leading backslashes are even with
the corresponding character. |
|
public static String |
replaceOctalEscapes(String text)Replaces an octal escape of up to three digits, when its leading backslashes are even, with the corresponding character. |
|
public static String |
replaceStandardEscapes(String text)Replaces \b, \t, \n, \f, \r,
\s (a space), {@code \"}, and {@code \'} when the leading
backslashes are even. |
|
public static String |
trimQuotations(String text, int quotationLength)Drops quotationLength characters from each end of
text. |
Slashy kind for a $/.../$ string. replaceEscapes
rewrites hex escapes, drops a backslash that continues a line, turns
$/ into /, and turns $$ into $.
Slashy kind for an ordinary string. replaceEscapes then
rewrites hex, octal, and standard escapes, drops a backslash that
continues a line, and turns \$ into $.
Slashy kind for a /.../ string. replaceEscapes
rewrites hex escapes, drops a backslash that continues a line, and
turns \/ into /.
Counts how many UTF-16 code units in text equal c.
text - source textc - code unit to countc occursCopied from Apache commons-lang3-3.6
Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the CharSequence. That functionality is available in isBlank().
cs - the CharSequence to check, may be nulltrue if the CharSequence is empty or null Reports whether the whole of text matches pattern.
text - text to testpattern - pattern applied with Matcher.matchestrue when pattern matches all of text Replaces every \r\n in text with \n. A lone
\r is left in place.
text - source texttext with CRLF pairs folded to LFThe modified implementation is based on StringUtils#replace(String text, String searchString, String replacement, int max), Apache commons-lang3-3.6
Replaces all occurrences of a String within another String.
A null reference passed to this method is a no-op.
StringUtils.replace(null, *, *) = null
StringUtils.replace("", *, *) = ""
StringUtils.replace("any", null, *) = "any"
StringUtils.replace("any", *, null) = "any"
StringUtils.replace("any", "", *) = "any"
StringUtils.replace("aba", "a", null) = "aba"
StringUtils.replace("aba", "a", "") = "b"
StringUtils.replace("aba", "a", "z") = "zbz"
text - text to search and replace in, may be nullsearchString - the String to search for, may be nullreplacement - the String to replace it with, may be nullnull if null String input Rewrites escapes in text according to slashyType.
NONE_SLASHY applies the full set used for an ordinary
string. SLASHY and DOLLAR_SLASHY apply the smaller
slashy sets. Any other slashyType is rejected.
text - source text, still containing escape sequencesslashyType - NONE_SLASHY, SLASHY, or
DOLLAR_SLASHYtext with those escapes replaced Replaces each \uXXXX whose leading backslashes are even with
the corresponding character. A match with an odd run of backslashes
is left unchanged. A string that contains no backslash is returned
as it was given.
text - source texttext with those hex escapes replacedReplaces an octal escape of up to three digits, when its leading backslashes are even, with the corresponding character. A match with an odd run of backslashes is left unchanged. A string that contains no backslash is returned as it was given.
text - source texttext with those octal escapes replaced Replaces \b, \t, \n, \f, \r,
\s (a space), {@code \"}, and {@code \'} when the leading
backslashes are even. Any other escaped character is kept. Each
remaining \\ then becomes one backslash. A string that
contains no backslash is returned as it was given.
text - source texttext with those standard escapes replaced Drops quotationLength characters from each end of
text. When text is exactly twice that long, the
result is empty.
text - quoted text, including the quote charactersquotationLength - number of characters in one quote delimiter