Package org.apache.commons.lang3
Class CharSetUtils
- java.lang.Object
-
- org.apache.commons.lang3.CharSetUtils
-
-
Constructor Summary
Constructors Constructor Description CharSetUtils()
CharSetUtils instances should NOT be constructed in standard programming.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containsAny(java.lang.String str, java.lang.String... set)
Takes an argument in set-syntax, see evaluateSet, and identifies whether any of the characters are 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
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.
-
-
-
Method Detail
-
containsAny
public static boolean containsAny(java.lang.String str, java.lang.String... set)
Takes an argument in set-syntax, see evaluateSet, and identifies whether any of the characters are present in the specified string.CharSetUtils.containsAny(null, *) = false CharSetUtils.containsAny("", *) = false CharSetUtils.containsAny(*, null) = false CharSetUtils.containsAny(*, "") = false CharSetUtils.containsAny("hello", "k-p") = true CharSetUtils.containsAny("hello", "a-d") = false
- Parameters:
str
- String to look for characters in, may be nullset
- String[] set of characters to identify, may be null- Returns:
- whether or not the characters in the set are in the primary string
- Since:
- 3.2
- See Also:
for set-syntax.
-
count
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
- Parameters:
str
- String to count characters in, may be nullset
- String[] set of characters to count, may be null- Returns:
- the character count, zero if null string input
- See Also:
for set-syntax.
-
delete
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"
- Parameters:
str
- String to delete characters from, may be nullset
- String[] set of characters to delete, may be null- Returns:
- the modified String,
null
if null string input - See Also:
for set-syntax.
-
keep
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"
- Parameters:
str
- String to keep characters from, may be nullset
- String[] set of characters to keep, may be null- Returns:
- the modified String,
null
if null string input - Since:
- 2.0
- See Also:
for set-syntax.
-
squeeze
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.CharSetUtils.squeeze(null, *) = null CharSetUtils.squeeze("", *) = "" CharSetUtils.squeeze(*, null) = * CharSetUtils.squeeze(*, "") = * CharSetUtils.squeeze("hello", "k-p") = "helo" CharSetUtils.squeeze("hello", "a-e") = "hello"
- Parameters:
str
- the string to squeeze, may be nullset
- the character set to use for manipulation, may be null- Returns:
- the modified String,
null
if null string input - See Also:
for set-syntax.
-
-