|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.pelzer.util.StringMan
public class StringMan
Utility class for string manipulation.
| Method Summary | |
|---|---|
static boolean |
areStringsEqual(String s1,
String s2)
null-safe string equality test. |
static String |
chop(String source,
int length)
Chops a string off after a certain number of characters. |
static String |
compressHexString(String inString)
Very simplistic compression method that encodes repeating characters into a smaller character, so '0000000000' becomes '^0j' where the '^' escapes the next two characters, '0' is the repeating character, and j encodes 10 repetitions. |
static String |
concat(String[] array,
String separator,
int fromIndex,
int toIndex)
Concats elements in array between fromIndex, inclusive, to toIndex, inclusive, inserting separator between them. |
static byte[] |
decodeStringToBytes(String hex)
Takes a string encoded in hex (00-FF), two chars per byte, and returns an array of bytes. |
static String |
decompressHexString(String in)
Decompresses a string encoded by compressHexString(java.lang.String) |
static String |
detokenize(String[] values,
String delimiter)
Converts a string array into a single string with values delimited by the specified delimiter. |
static String |
encodeBytesToString(byte[] bytes)
Takes a byte array and returns a hex string (00-FF) encoded two chars per byte. |
static String |
escapeForXML(String inString)
Makes a string xml-safe, converting &<>"' to their &token; equivalents, and converting all other non-safe chars to their version. |
static String |
getFirstLine(String s)
|
static String |
getNullAsEmptyString(String input)
Returns an empty string if input is null, otherwise returns the original input string untouched. |
static String |
getNullAsValue(String input,
String value)
Returns the specified string value if input is null, otherwise returns the original input string untouched. |
static String |
getStackTrace(Throwable ex)
|
static String |
getUS7ASCIIEquiv(String convertString)
Converts a string with possible high-ascii values into their ascii7 equiv., for instance 'é' maps to 'e'. |
static boolean |
isEmpty(String s)
|
static boolean |
isStringTrue(String in)
Returns true if the string is 'TRUE' or 'YES' or '1', case insensitive. |
static String |
padLeftJustified(String string,
int length)
"foo" becomes "foo " |
static String |
padLeftJustified(String string,
int length,
String padString)
|
static String |
padRightJustified(String string,
int length)
"foo" becomes " foo" |
static String |
padRightJustified(String string,
int length,
String padString)
|
static int[] |
parseInts(String[] array)
Takes an array of Strings with integer values and returns an array of ints, or throws a NumberFormatException if there's a problem. |
static long[] |
parseLongs(String[] array)
Takes an array of Strings with long values and returns an array of longs, or throws a NumberFormatException if there's a problem. |
static String |
replace(String haystack,
String needle,
String... replacements)
Same behavior as replace(String, String, String) but cycles through the replacements,
so replace("xxx","x","1","2","3") would return "123". |
static String |
replace(String haystack,
String needle,
String replacement)
Replaces all occurences of a String with another string, using the fastest method we could devise. |
static String |
replaceFirst(String source,
String find,
String replace)
Replaces first occurence of a String with another string |
static String |
stripNonAlphaNumericCharacters(String input)
Strips all non A-Z/0-9 characters from the input string. |
static String |
stripNonEmailCharacters(String input)
Strips everything except A-Z a-z 0-9 @ . |
static String |
stripWhitespace(String input)
Strips all characters c satisfying Character.isWhitespace(c). |
static String |
toInitialCaps(String inString)
Takes the inString and capitalizes every leter that occurs after a non-alpha character. "I like pizza" becomes "I Like Pizza" "DON'T EAT THAT" becomes "Don'T Eat That" |
static String[] |
tokenize(String s)
Splits string into an array using StringTokenizer's default delimeter set which is * " \t\n\r\f": the space character, the tab character, the
newline character, the carriage-return character, and the form-feed character. |
static String[] |
tokenize(String s,
String delimiter)
Splits string into an array using the given delimiter |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static String getNullAsEmptyString(String input)
input - String to be evaluated
public static String getNullAsValue(String input,
String value)
input - String to be evaluatedvalue - String to substitute if input is null
public static String replaceFirst(String source,
String find,
String replace)
public static boolean isEmpty(String s)
public static String getFirstLine(String s)
public static String getStackTrace(Throwable ex)
public static boolean isStringTrue(String in)
public static String chop(String source,
int length)
source - length -
public static String replace(String haystack,
String needle,
String replacement)
public static String replace(String haystack,
String needle,
String... replacements)
replace(String, String, String) but cycles through the replacements,
so replace("xxx","x","1","2","3") would return "123". If you don't give enough replacements,
needles will be left in the resulting string. If you don't have enough instances of needle to
fit all replacements, no foul, you just won't see those replacements.
public static String escapeForXML(String inString)
public static String toInitialCaps(String inString)
public static String padLeftJustified(String string,
int length)
public static String padLeftJustified(String string,
int length,
String padString)
padLeftJustified(String, int)
public static String padRightJustified(String string,
int length)
public static String padRightJustified(String string,
int length,
String padString)
public static byte[] decodeStringToBytes(String hex)
decompressHexString(java.lang.String)
public static String stripWhitespace(String input)
public static String stripNonAlphaNumericCharacters(String input)
public static String stripNonEmailCharacters(String input)
public static String encodeBytesToString(byte[] bytes)
public static String compressHexString(String inString)
public static String decompressHexString(String in)
compressHexString(java.lang.String)
public static String getUS7ASCIIEquiv(String convertString)
public static String concat(String[] array,
String separator,
int fromIndex,
int toIndex)
public static String[] tokenize(String s)
" \t\n\r\f": the space character, the tab character, the
newline character, the carriage-return character, and the form-feed character.
StringTokenizer
public static String[] tokenize(String s,
String delimiter)
StringTokenizer
public static String detokenize(String[] values,
String delimiter)
public static boolean areStringsEqual(String s1,
String s2)
public static long[] parseLongs(String[] array)
NumberFormatException if there's a problem.
public static int[] parseInts(String[] array)
NumberFormatException if there's a problem.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||