public class StringUtil2
extends java.lang.Object
Constructor and Description |
---|
StringUtil2() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
allow(java.lang.String x,
java.lang.String allowChars,
char replaceChar)
Replace any char not alphanumeric or in allowChars by replaceChar.
|
static java.lang.String |
breakText(java.lang.String text,
java.lang.String insert,
int lineSize)
Convert the given text to html by adding <br>.
|
static java.lang.String |
breakTextAtWords(java.lang.String text,
java.lang.String insert,
int lineSize)
Break the given text into lines, respecting word boundaries (blank space).
|
static java.lang.String |
cleanup(byte[] h)
Delete any non-printable characters
|
static java.lang.String |
cleanup(java.lang.String s) |
static java.lang.String |
collapseWhitespace(java.lang.String s)
Collapse continuous whitespace into one single " ".
|
static java.lang.String |
escape(java.lang.String x,
java.lang.String okChars)
Escape any char not alphanumeric or in okChars.
|
static java.lang.String |
escape2(java.lang.String x,
java.lang.String reservedChars)
Escape any char in reservedChars.
|
static java.lang.String |
filter(java.lang.String x,
java.lang.String okChars)
Remove any char not alphanumeric or in okChars.
|
static java.lang.String |
filter7bits(java.lang.String s)
Remove all but printable ascii
|
static java.util.List<java.lang.String> |
getTokens(java.lang.String fullString,
java.lang.String sep) |
static java.lang.String |
ignoreescape2(java.lang.String x,
java.lang.String reservedChars) |
static void |
main(java.lang.String[] args) |
static void |
main2(java.lang.String[] args) |
static void |
main3() |
static java.lang.String |
makeValidCdmObjectName(java.lang.String name) |
static int |
match(java.lang.String s1,
java.lang.String s2)
Count number of chars that match in two strings, starting from front.
|
static java.lang.String |
padLeft(java.lang.String s,
int desiredLength)
Pad the given string with spaces on the left up to the given length.
|
static java.lang.String |
padLeft(java.lang.String s,
int desiredLength,
java.lang.String padString)
Pad the given string with padString on the left up to the given length.
|
static java.lang.String |
padRight(java.lang.String s,
int desiredLength)
Pad the given string with spaces on the right up to the given length.
|
static java.lang.String |
padRight(java.lang.String s,
int desiredLength,
java.lang.String padString)
Pad the given string with padString on the right up to the given length.
|
static java.lang.String |
padZero(int value,
int numDigits)
Left pad the given value with zeros up to the number of digits
|
static java.lang.String |
quoteHtmlContent(java.lang.String x)
Replace special characters with entities for HTML content.
|
static java.lang.String |
quoteXmlAttribute(java.lang.String x)
Replace special characters with entities for XML attributes.
|
static java.lang.String |
quoteXmlContent(java.lang.String x)
Replace special characters with entities for XML attributes.
|
static void |
remove(java.lang.StringBuilder sb,
java.lang.String out)
Remove any of the characters in out from sb
|
static java.lang.String |
remove(java.lang.String s,
int c)
Remove all occurrences of the character c in the string s.
|
static java.lang.String |
remove(java.lang.String s,
java.lang.String sub)
Remove all occurrences of the substring sub in the string s.
|
static java.lang.String |
removeFromEnd(java.lang.String s,
int c)
Remove all occurrences of the character c at the end of s.
|
static java.lang.String |
removeFromEnd(java.lang.String s,
java.lang.String suffix) |
static java.lang.String |
removeWhitespace(java.lang.String inputString)
Remove any whitespace (ie., Character.isWhitespace) from the input string.
|
static void |
replace(java.lang.StringBuilder sb,
char out,
java.lang.String in)
Replace any char "out" in sb with String "in".
|
static void |
replace(java.lang.StringBuilder sb,
java.lang.String out,
java.lang.String in)
Replace any of the characters from out with corresponding character from in
|
static java.lang.String |
replace(java.lang.String x,
char[] replaceChar,
java.lang.String[] replaceWith)
Replace all occurrences of any char in replaceChar with corresponding String in replaceWith
|
static java.lang.String |
replace(java.lang.String s,
char out,
java.lang.String in)
Replace any char "out" in s with "in".
|
static java.lang.String |
replace(java.lang.String string,
java.lang.String pattern,
java.lang.String value)
Replaces all occurrences of "pattern" in "string" with "value"
|
static java.lang.String[] |
splitString(java.lang.String source)
Split a string on one or more whitespace.
|
static void |
substitute(java.lang.StringBuilder sbuff,
java.lang.String match,
java.lang.String subst)
Find all occurences of the "match" in original, and substitute the "subst" string,
directly into the original.
|
static java.lang.String |
substitute(java.lang.String original,
java.lang.String[] match,
java.lang.String[] subst)
Find all occurences of match strings in original, and substitute the corresponding
subst string.
|
static java.lang.String |
substitute(java.lang.String original,
java.lang.String match,
java.lang.String subst)
Find all occurences of the "match" in original, and substitute the "subst" string.
|
static java.lang.String |
trim(java.lang.String s,
int bad)
Remove bad char from beginning or end of string
|
static java.lang.String |
unescape(java.lang.String x)
This finds any '%xx' and converts to the equivalent char.
|
static java.lang.String |
unquoteHtmlContent(java.lang.String x) |
static java.lang.String |
unquoteXmlAttribute(java.lang.String x)
Reverse XML quoting to recover the original string.
|
static java.lang.String |
unquoteXmlContent(java.lang.String x)
Reverse XML quoting to recover the original string.
|
static void |
unreplace(java.lang.StringBuilder sb,
java.lang.String out,
char in)
Replace any String "out" in sb with char "in".
|
static java.lang.String |
unreplace(java.lang.String x,
java.lang.String[] orgReplace,
char[] orgChar)
Replace all occurences of orgReplace with orgChar; inverse of replace().
|
public static java.lang.String allow(java.lang.String x, java.lang.String allowChars, char replaceChar)
x
- operate on this stringallowChars
- these are ok.replaceChar
- thar char to replacepublic static java.lang.String breakTextAtWords(java.lang.String text, java.lang.String insert, int lineSize)
text
- The text to convertinsert
- break to insertlineSize
- line size to insert atpublic static java.lang.String cleanup(byte[] h)
h
- byte arraypublic static java.lang.String cleanup(java.lang.String s)
public static java.lang.String filter(java.lang.String x, java.lang.String okChars)
x
- filter this stringokChars
- these are ok.public static java.lang.String filter7bits(java.lang.String s)
s
- filter this stringpublic static java.lang.String makeValidCdmObjectName(java.lang.String name)
public static int match(java.lang.String s1, java.lang.String s2)
s1
- compare this strings2
- compare this stringpublic static java.lang.String padZero(int value, int numDigits)
value
- The value.numDigits
- number of digitspublic static java.lang.String padLeft(java.lang.String s, int desiredLength)
s
- String to paddesiredLength
- ending lengthpublic static java.lang.String padLeft(java.lang.String s, int desiredLength, java.lang.String padString)
s
- String to paddesiredLength
- ending lengthpadString
- String to pad with (e.g, " ")public static java.lang.String padRight(java.lang.String s, int desiredLength)
s
- String to paddesiredLength
- ending lengthpublic static java.lang.String padRight(java.lang.String s, int desiredLength, java.lang.String padString)
s
- String to paddesiredLength
- ending lengthpadString
- String to pad with (e.g, " ")public static java.lang.String quoteHtmlContent(java.lang.String x)
x
- string to quotepublic static java.lang.String unquoteHtmlContent(java.lang.String x)
public static java.lang.String quoteXmlContent(java.lang.String x)
x
- string to quotepublic static java.lang.String unquoteXmlContent(java.lang.String x)
x
- string to quotepublic static java.lang.String quoteXmlAttribute(java.lang.String x)
x
- string to quotepublic static java.lang.String unquoteXmlAttribute(java.lang.String x)
x
- string to quotepublic static java.lang.String remove(java.lang.String s, java.lang.String sub)
s
- operate on this stringsub
- remove all occurrences of this substring.public static java.lang.String remove(java.lang.String s, int c)
s
- operate on this stringc
- remove all occurrences of this character.public static java.lang.String removeFromEnd(java.lang.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 java.lang.String removeFromEnd(java.lang.String s, java.lang.String suffix)
public static java.lang.String removeWhitespace(java.lang.String inputString)
inputString
- The string to remove the whitespace.public static java.lang.String collapseWhitespace(java.lang.String s)
s
- operate on this stringpublic static java.lang.String replace(java.lang.String s, char out, java.lang.String in)
s
- string to replaceout
- replace this characterin
- with this stringpublic static java.lang.String replace(java.lang.String x, char[] replaceChar, java.lang.String[] replaceWith)
x
- operate on this stringreplaceChar
- get rid of thesereplaceWith
- replace with thesepublic static java.lang.String replace(java.lang.String string, java.lang.String pattern, java.lang.String value)
string
- string to mungepattern
- pattern to replacevalue
- replacement valuepublic static java.lang.String unreplace(java.lang.String x, java.lang.String[] orgReplace, char[] orgChar)
x
- operate on this stringorgReplace
- get rid of theseorgChar
- replace with thesepublic static java.lang.String substitute(java.lang.String original, java.lang.String match, java.lang.String subst)
original
- starting stringmatch
- string to matchsubst
- string to substitutepublic static java.lang.String escape(java.lang.String x, java.lang.String okChars)
x
- escape this stringokChars
- these are ok.public static java.lang.String unescape(java.lang.String x)
x
- operate on this Stringpublic static java.lang.String[] splitString(java.lang.String source)
source
- split this stringpublic static java.lang.String substitute(java.lang.String original, java.lang.String[] match, java.lang.String[] subst)
original
- starting stringmatch
- array of strings to matchsubst
- array of strings to substitutepublic static java.util.List<java.lang.String> getTokens(java.lang.String fullString, java.lang.String sep) throws java.lang.Exception
java.lang.Exception
public static void remove(java.lang.StringBuilder sb, java.lang.String out)
sb
- the StringBuilderout
- get rid of any of these characterspublic static void replace(java.lang.StringBuilder sb, char out, java.lang.String in)
sb
- StringBuilder to replaceout
- repalce this characterin
- with this stringpublic static void unreplace(java.lang.StringBuilder sb, java.lang.String out, char in)
sb
- StringBuilder to replaceout
- repalce this Stringin
- with this charpublic static void replace(java.lang.StringBuilder sb, java.lang.String out, java.lang.String in)
sb
- the StringBuilderout
- get rid of any of these charactersin
- replacing with the character at same indexpublic static void substitute(java.lang.StringBuilder sbuff, java.lang.String match, java.lang.String subst)
sbuff
- starting string buffermatch
- string to matchsubst
- string to substitutepublic static java.lang.String trim(java.lang.String s, int bad)
s
- operate on thispublic static void main2(java.lang.String[] args)
public static void main3()
public static void main(java.lang.String[] args) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static java.lang.String escape2(java.lang.String x, java.lang.String reservedChars)
x
- escape this stringreservedChars
- these must be replacedpublic static java.lang.String ignoreescape2(java.lang.String x, java.lang.String reservedChars)
public static java.lang.String breakText(java.lang.String text, java.lang.String insert, int lineSize)
text
- The text to convertinsert
- string to insertlineSize
- line size to insert at