public class StringUtil2 extends Object
Constructor and Description |
---|
StringUtil2() |
Modifier and Type | Method and Description |
---|---|
static String |
allow(String x,
String allowChars,
char replaceChar)
Replace any char not alphanumeric or in allowChars by replaceChar.
|
static String |
breakTextAtWords(String text,
String insert,
int lineSize)
Break the given text into lines, respecting word boundaries (blank space).
|
static String |
cleanup(byte[] h)
Delete any non-printable characters
|
static String |
cleanup(String s) |
static String |
collapseWhitespace(String s)
Collapse continuous whitespace into one single " ".
|
static String |
escape(String x,
String okChars)
Escape any char not alphanumeric or in okChars.
|
static String |
filter(String x,
String okChars)
Remove any char not alphanumeric or in okChars.
|
static String |
filter7bits(String s)
Remove all but printable ascii
|
static List<String> |
getTokens(String fullString,
String sep) |
static String |
makeValidCdmObjectName(String name) |
static int |
match(String s1,
String s2)
Count number of chars that match in two strings, starting from front.
|
static String |
padLeft(String s,
int desiredLength)
Pad the given string with spaces on the left up to the given length.
|
static String |
padLeft(String s,
int desiredLength,
String padString)
Pad the given string with padString on the left up to the given length.
|
static String |
padRight(String s,
int desiredLength)
Pad the given string with spaces on the right up to the given length.
|
static String |
padRight(String s,
int desiredLength,
String padString)
Pad the given string with padString on the right up to the given length.
|
static String |
padZero(int value,
int numDigits)
Left pad the given value with zeros up to the number of digits
|
static String |
quoteHtmlContent(String x)
Deprecated.
legacy only, use HtmlEscapers.htmlEscaper()
|
static String |
remove(String s,
int c)
Remove all occurrences of the character c in the string s.
|
static String |
remove(String s,
String sub)
Remove all occurrences of the substring sub in the string s.
|
static void |
removeAll(StringBuilder sb,
String out)
Remove any of the characters in out from sb
|
static String |
removeFromEnd(String s,
int c)
Remove all occurrences of the character c at the end of s.
|
static String |
removeFromEnd(String s,
String suffix) |
static String |
removeWhitespace(String inputString)
Remove any whitespace (ie., Character.isWhitespace) from the input string.
|
static void |
replace(StringBuilder sb,
char out,
String in)
Replace any char "out" in sb with String "in".
|
static void |
replace(StringBuilder sb,
String out,
String in)
Replace any of the characters from out with corresponding character from in
|
static String |
replace(String x,
char[] replaceChar,
String[] replaceWith)
Replace all occurrences of any char in replaceChar with corresponding String in replaceWith
|
static String |
replace(String s,
char out,
String in)
Replace any char "out" in s with "in".
|
static String |
replace(String string,
String pattern,
String value)
Replaces all occurrences of "pattern" in "string" with "value"
|
static Iterable<String> |
split(String source) |
static String[] |
splitString(String source)
Deprecated.
use StringUtil2.split()
|
static void |
substitute(StringBuilder sbuff,
String match,
String subst)
Find all occurences of the "match" in original, and substitute the "subst" string,
directly into the original.
|
static String |
substitute(String original,
String[] match,
String[] subst)
Find all occurences of match strings in original, and substitute the corresponding
subst string.
|
static String |
substitute(String original,
String match,
String subst)
Find all occurrences of the "match" in original, and substitute the "subst" string.
|
static String |
trim(String s,
int bad)
Remove bad char from beginning or end of string
|
static String |
unescape(String x)
This finds any '%xx' and converts to the equivalent char.
|
static void |
unreplace(StringBuilder sb,
String out,
char in)
Replace any String "out" in sb with char "in".
|
static String |
unreplace(String x,
String[] orgReplace,
char[] orgChar)
Replace all occurrences of orgReplace with orgChar; inverse of replace().
|
public static String allow(String x, String allowChars, char replaceChar)
x
- operate on this stringallowChars
- these are ok.replaceChar
- thar char to replacepublic static String breakTextAtWords(String text, String insert, int lineSize)
text
- The text to convertinsert
- break to insertlineSize
- line size to insert atpublic static String cleanup(byte[] h)
h
- byte arraypublic static String filter(String x, String okChars)
x
- filter this stringokChars
- these are ok.public static String filter7bits(String s)
s
- filter this stringpublic static int match(String s1, String s2)
s1
- compare this strings2
- compare this stringpublic static String padZero(int value, int numDigits)
value
- The value.numDigits
- number of digitspublic static String padLeft(String s, int desiredLength)
s
- String to paddesiredLength
- ending lengthpublic static String padLeft(String s, int desiredLength, String padString)
s
- String to paddesiredLength
- ending lengthpadString
- String to pad with (e.g, " ")public static String padRight(String s, int desiredLength)
s
- String to paddesiredLength
- ending lengthpublic static String padRight(String s, int desiredLength, String padString)
s
- String to paddesiredLength
- ending lengthpadString
- String to pad with (e.g, " ")public static String remove(String s, String sub)
s
- operate on this stringsub
- remove all occurrences of this substring.public static String remove(String s, int c)
s
- operate on this stringc
- remove all occurrences of this character.public static String removeFromEnd(String s, int c)
s
- operate on this stringc
- remove all occurrences of this character that are at the end of the string.public static String removeWhitespace(String inputString)
inputString
- The string to remove the whitespace.public static String collapseWhitespace(String s)
s
- operate on this stringpublic static String replace(String s, char out, String in)
s
- string to replaceout
- replace this characterin
- with this stringpublic static String replace(String x, char[] replaceChar, String[] replaceWith)
x
- operate on this stringreplaceChar
- get rid of thesereplaceWith
- replace with thesepublic static String replace(String string, String pattern, String value)
string
- string to mungepattern
- pattern to replacevalue
- replacement valuepublic static String unreplace(String x, String[] orgReplace, char[] orgChar)
x
- operate on this stringorgReplace
- get rid of theseorgChar
- replace with thesepublic static String substitute(String original, String match, String subst)
original
- starting stringmatch
- string to matchsubst
- string to substitutepublic static String escape(String x, String okChars)
x
- escape this stringokChars
- these are ok.public static String unescape(String x)
x
- operate on this String@Deprecated public static String[] splitString(String source)
source
- split this stringpublic static String substitute(String original, String[] match, String[] subst)
original
- starting stringmatch
- array of strings to matchsubst
- array of strings to substitutepublic static void removeAll(StringBuilder sb, String out)
sb
- the StringBuilderout
- get rid of any of these characterspublic static void replace(StringBuilder sb, char out, String in)
sb
- StringBuilder to replaceout
- repalce this characterin
- with this stringpublic static void unreplace(StringBuilder sb, String out, char in)
sb
- StringBuilder to replaceout
- repalce this Stringin
- with this charpublic static void replace(StringBuilder sb, String out, String in)
sb
- the StringBuilderout
- get rid of any of these charactersin
- replacing with the character at same indexpublic static void substitute(StringBuilder sbuff, String match, String subst)
sbuff
- starting string buffermatch
- string to matchsubst
- string to substitutepublic static String trim(String s, int bad)
s
- operate on this