public class CharSetUtils
extends java.lang.Object
Operations on CharSet
s.
This class handles null
input gracefully.
An exception will not be thrown for a null
input.
Each method documents its behaviour in more detail.
#ThreadSafe#
CharSet
Constructor and Description |
---|
CharSetUtils()
CharSetUtils instances should NOT be constructed in standard programming.
|
Modifier and Type | Method and Description |
---|---|
static int |
count(java.lang.String str,
java.lang.String set)
Takes an argument in set-syntax, see evaluateSet,
and returns the number of characters present in the specified string.
|
static int |
count(java.lang.String str,
java.lang.String[] set)
Takes an argument in set-syntax, see evaluateSet,
and returns the number of characters present in the specified string.
|
static java.lang.String |
delete(java.lang.String str,
java.lang.String set)
Takes an argument in set-syntax, see evaluateSet,
and deletes any of characters present in the specified string.
|
static java.lang.String |
delete(java.lang.String str,
java.lang.String[] set)
Takes an argument in set-syntax, see evaluateSet,
and deletes any of characters present in the specified string.
|
static CharSet |
evaluateSet(java.lang.String[] set)
Deprecated.
Use
CharSet.getInstance(String[]) .
Method will be removed in Commons Lang 3.0. |
static java.lang.String |
keep(java.lang.String str,
java.lang.String set)
Takes an argument in set-syntax, see evaluateSet,
and keeps any of characters present in the specified string.
|
static java.lang.String |
keep(java.lang.String str,
java.lang.String[] set)
Takes an argument in set-syntax, see evaluateSet,
and keeps any of characters present in the specified string.
|
static java.lang.String |
squeeze(java.lang.String str,
java.lang.String set)
Squeezes any repetitions of a character that is mentioned in the
supplied set.
|
static java.lang.String |
squeeze(java.lang.String str,
java.lang.String[] set)
Squeezes any repetitions of a character that is mentioned in the
supplied set.
|
static java.lang.String |
translate(java.lang.String str,
java.lang.String searchChars,
java.lang.String replaceChars)
Deprecated.
Use
StringUtils.replaceChars(String, String, String) .
Method will be removed in Commons Lang 3.0.
NOTE: StringUtils#replaceChars behaves differently when 'searchChars' is longer
than 'replaceChars'. CharSetUtils#translate will use the last char of the replacement
string whereas StringUtils#replaceChars will delete |
public CharSetUtils()
CharSetUtils instances should NOT be constructed in standard programming.
Instead, the class should be used as CharSetUtils.evaluateSet(null);
.
This constructor is public to permit tools that require a JavaBean instance to operate.
public static CharSet evaluateSet(java.lang.String[] set)
CharSet.getInstance(String[])
.
Method will be removed in Commons Lang 3.0.Creates a CharSet
instance which allows a certain amount of
set logic to be performed.
The syntax is:
CharSetUtils.evaluateSet(null) = null CharSetUtils.evaluateSet([]) = CharSet matching nothing CharSetUtils.evaluateSet(["a-e"]) = CharSet matching a,b,c,d,e
set
- the set, may be nullnull
if null inputpublic static java.lang.String squeeze(java.lang.String str, java.lang.String set)
Squeezes any repetitions of a character that is mentioned in the supplied set.
CharSetUtils.squeeze(null, *) = null CharSetUtils.squeeze("", *) = "" CharSetUtils.squeeze(*, null) = * CharSetUtils.squeeze(*, "") = * CharSetUtils.squeeze("hello", "k-p") = "helo" CharSetUtils.squeeze("hello", "a-e") = "hello"
str
- the string to squeeze, may be nullset
- the character set to use for manipulation, may be nullnull
if null string inputfor set-syntax.
public static java.lang.String squeeze(java.lang.String str, java.lang.String[] set)
Squeezes any repetitions of a character that is mentioned in the supplied set.
An example is:
str
- the string to squeeze, may be nullset
- the character set to use for manipulation, may be nullnull
if null string inputfor set-syntax.
public static int count(java.lang.String str, java.lang.String set)
Takes an argument in set-syntax, see evaluateSet, and returns the number of characters present in the specified string.
CharSetUtils.count(null, *) = 0 CharSetUtils.count("", *) = 0 CharSetUtils.count(*, null) = 0 CharSetUtils.count(*, "") = 0 CharSetUtils.count("hello", "k-p") = 3 CharSetUtils.count("hello", "a-e") = 1
str
- String to count characters in, may be nullset
- String set of characters to count, may be nullfor set-syntax.
public static int count(java.lang.String str, java.lang.String[] set)
Takes an argument in set-syntax, see evaluateSet, and returns the number of characters present in the specified string.
An example would be:
str
- String to count characters in, may be nullset
- String[] set of characters to count, may be nullfor set-syntax.
public static java.lang.String keep(java.lang.String str, java.lang.String set)
Takes an argument in set-syntax, see evaluateSet, and keeps any of characters present in the specified string.
CharSetUtils.keep(null, *) = null CharSetUtils.keep("", *) = "" CharSetUtils.keep(*, null) = "" CharSetUtils.keep(*, "") = "" CharSetUtils.keep("hello", "hl") = "hll" CharSetUtils.keep("hello", "le") = "ell"
str
- String to keep characters from, may be nullset
- String set of characters to keep, may be nullnull
if null string inputfor set-syntax.
public static java.lang.String keep(java.lang.String str, java.lang.String[] set)
Takes an argument in set-syntax, see evaluateSet, and keeps any of characters present in the specified string.
An example would be:
str
- String to keep characters from, may be nullset
- String[] set of characters to keep, may be nullnull
if null string inputfor set-syntax.
public static java.lang.String delete(java.lang.String str, java.lang.String set)
Takes an argument in set-syntax, see evaluateSet, and deletes any of characters present in the specified string.
CharSetUtils.delete(null, *) = null CharSetUtils.delete("", *) = "" CharSetUtils.delete(*, null) = * CharSetUtils.delete(*, "") = * CharSetUtils.delete("hello", "hl") = "eo" CharSetUtils.delete("hello", "le") = "ho"
str
- String to delete characters from, may be nullset
- String set of characters to delete, may be nullnull
if null string inputfor set-syntax.
public static java.lang.String delete(java.lang.String str, java.lang.String[] set)
Takes an argument in set-syntax, see evaluateSet, and deletes any of characters present in the specified string.
An example would be:
str
- String to delete characters from, may be nullset
- String[] set of characters to delete, may be nullnull
if null string inputfor set-syntax.
public static java.lang.String translate(java.lang.String str, java.lang.String searchChars, java.lang.String replaceChars)
StringUtils.replaceChars(String, String, String)
.
Method will be removed in Commons Lang 3.0.
NOTE: StringUtils#replaceChars behaves differently when 'searchChars' is longer
than 'replaceChars'. CharSetUtils#translate will use the last char of the replacement
string whereas StringUtils#replaceChars will deleteTranslate characters in a String. This is a multi character search and replace routine.
An example is:
If the length of characters to search for is greater than the length of characters to replace, then the last character is used.
CharSetUtils.translate(null, *, *) = null CharSetUtils.translate("", *, *) = ""
str
- String to replace characters in, may be nullsearchChars
- a set of characters to search for, must not be nullreplaceChars
- a set of characters to replace, must not be null or empty ("")null
if null string inputjava.lang.NullPointerException
- if searchChars
or replaceChars
is null
java.lang.ArrayIndexOutOfBoundsException
- if replaceChars
is empty ("")"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"