| java.lang.Object org.lateralnz.common.util.StringUtils
StringUtils | final public class StringUtils implements Constants(Code) | | common string utility functions
author: J R Briggs |
Method Summary | |
final public static int | countOccurrences(String s, char c) | final public static int | countOccurrences(StringBuffer sb, char c) | final public static String | degzip(byte[] b) | final public static String | escape(String s) | final public static List | findRegex(String s, String pattern) | final public static String | format(String pattern, Object[] arguments) | final public static String | format(String pattern, String argument) | final public static String | fromArray(String[] s, String delim) | final public static String | fromArray(String[] s, String delim, int start, int len) | final public static String | fromList(List l, String delim) | final public static String | fromMap(Map map, char delim) create a string based upon the contents of a map. | final public static String | getFromDelimitedString(String s, String delim, int index) | final public static Pattern | getPattern(String pattern) | public static String | getRandomString(int len) | final public static String | getTagValue(String s, String tagStart, String tagEnd) given a string and the start and end of a tag return the contents of the tag. | final public static byte[] | gzip(String s) | final public static boolean | isEmpty(String s) | final public static boolean | isEmpty(Object o) | final public static boolean | isEqual(String s1, String s2) | final public static String | isNull(String s, String replacement) | final public static boolean | isNumeric(String s) | final public static String | lpad(String text, char pad, int length) | final public static boolean | matches(String s, String pattern) | final public static String | readFrom(Reader r) | final public static String | readFrom(Reader r, int size) | final public static String | readFromFile(String filename) | final public static String | remove(String s, String chars) remove all occurences of a list of characters from a string. | final public static void | replace(StringBuffer sb, String oldstr, String newstr) | final public static String | replace(String s, String oldstr, String newstr) | final public static String | replaceChars(String s, String chars, char newChar) | final public static String | replaceTag(String s, String tagStart, String tagEnd, String replace) replace all references to a 'tag' within a string. | final public static String | rpad(String text, char pad, int length) | final public static List | splitRegex(String s, String pattern) | final public static String | strip(String s, String chars) | final public static String | stripLTSpaces(String s) | final public static String[] | toArray(String s, String delim) | final public static String[] | toArray(String s, String delim, boolean returnDelims) | final public static String | toDirectory(String filename) makes sure that a directory filename ends with the file separator. | final public static String | toHTML(String s) | final public static String | toHTML(String s, boolean includeBR) convert a string into an 'HTML-ready' string, handling special characters. | final public static String | toHex(byte b) | final public static String | toHex(byte[] b) | final public static List | toList(String s, String delim, List list) | final public static List | toList(String s, String delim) | final public static String | toMD5Digest(String s) | final public static Map | toMap(String s, String delim) turn a string into a map of param=value objects based upon a delimiter. | final public static void | toMap(Map m, String s, String delim) | final public static String | toSHADigest(String s) | final public static String | unencode(String s) | final public static String | unescape(String s) |
countOccurrences | final public static int countOccurrences(String s, char c)(Code) | | count the occurrences of a character in a string
|
findRegex | final public static List findRegex(String s, String pattern)(Code) | | return a list of regular expression groups given a string and a regex grouping pattern
|
format | final public static String format(String pattern, Object[] arguments)(Code) | | a quick and dirty wrapper over MessageFormat.format, so we don't need
to import it into JSPs as well as org.lateralnz.util.*
|
format | final public static String format(String pattern, String argument)(Code) | | a wrapper for MessageFormat.format that takes a single argument
rather than an array
|
fromArray | final public static String fromArray(String[] s, String delim, int start, int len)(Code) | | turn an array of strings into a single delimited string
Parameters: s - the array of strings to use Parameters: delim - the delimiter to use between each value Parameters: start - the start position of the array Parameters: len - the number of elements to use from the array |
fromList | final public static String fromList(List l, String delim)(Code) | | turn a list of strings into a single delimited string
|
fromMap | final public static String fromMap(Map map, char delim)(Code) | | create a string based upon the contents of a map. The string will be constructed
as key=value[DELIM]key=value[DELIM]..., where [DELIM] is specified in the call to
this method. For example:
fromMap(m, ',')
would return: key1=value1,key2=value2,key3=value3,etc
|
getFromDelimitedString | final public static String getFromDelimitedString(String s, String delim, int index)(Code) | | parse a delimited string returning the element at the specified index
Parameters: s - the string to parse Parameters: delim - the delimiters Parameters: index - the index value to return |
getRandomString | public static String getRandomString(int len)(Code) | | create a random string of a specified length
|
getTagValue | final public static String getTagValue(String s, String tagStart, String tagEnd)(Code) | | given a string and the start and end of a tag return the contents of the tag.
For example, given the string: "hello this <!-- is a test -->" and a tag start
of "<!--" and a tag end of "-->", this method should return " is a test "
|
isEmpty | final public static boolean isEmpty(String s)(Code) | | return true if a string is null or empty (in other words equals(\"\"))
|
isEmpty | final public static boolean isEmpty(Object o)(Code) | | return true if an object is null, or it is a string and empty
|
isEqual | final public static boolean isEqual(String s1, String s2)(Code) | | check for equality between two strings, taking nulls into account
|
isNull | final public static String isNull(String s, String replacement)(Code) | | if a string is null, then return the specified replacement
Parameters: s - the string to check for null Parameters: replacement - the string to return if s is null |
isNumeric | final public static boolean isNumeric(String s)(Code) | | Check if a string is numeric (digit chars only)
|
lpad | final public static String lpad(String text, char pad, int length)(Code) | | left pad a string with a certain character so that it equals the specified
length
|
matches | final public static boolean matches(String s, String pattern) throws PatternSyntaxException(Code) | | return true if a particular string matches the regular expression
Parameters: s - the string to check Parameters: pattern - the regular expression to look for |
readFrom | final public static String readFrom(Reader r)(Code) | | read the contents of the specified reader
|
readFrom | final public static String readFrom(Reader r, int size)(Code) | | read the contents of the specified reader up to the specified size
|
readFromFile | final public static String readFromFile(String filename)(Code) | | read the contents of a file and return as a string
|
remove | final public static String remove(String s, String chars)(Code) | | remove all occurences of a list of characters from a string. for example:
remove("This is a test", " ");
should return "Thisisatest".
Parameters: s - the string to remove characters from Parameters: chars - the list of characters to remove |
replace | final public static void replace(StringBuffer sb, String oldstr, String newstr)(Code) | | replace all references of a string in a stringbuffer with the contents
of a replacement string
|
replace | final public static String replace(String s, String oldstr, String newstr)(Code) | | replace all occurrences of a string with the contents of another string
Parameters: s - the string to search Parameters: oldstr - the string pattern to look for Parameters: newstr - the string pattern to replace with |
replaceTag | final public static String replaceTag(String s, String tagStart, String tagEnd, String replace)(Code) | | replace all references to a 'tag' within a string. A tag is a section of text
defined with a start string and and end string.
For example:
replaceTag("this is a test blah blah", "", "");
Would be expected to return "this is a test blah blah"
|
rpad | final public static String rpad(String text, char pad, int length)(Code) | | right pad a string with a character so that the length is the same as that
specified by the length param
|
splitRegex | final public static List splitRegex(String s, String pattern) throws PatternSyntaxException(Code) | | split a string based upon a regular expression pattern
For example: splitRegex("a,b,c,d,e", ",")
would return a list containing a, b, c, d, and e as the elements
|
strip | final public static String strip(String s, String chars)(Code) | | strip all occurrences of characters in a string from a specified string
Parameters: s - the string to search Parameters: chars - a string of characters to remove from s |
stripLTSpaces | final public static String stripLTSpaces(String s)(Code) | | strip leading a trailing spaces from a string based upon line delimiters
|
toArray | final public static String[] toArray(String s, String delim)(Code) | | turn a string into an array of strings (delimiters are not returned as part of the array)
Parameters: s - the string to convert Parameters: delim - the delimiters to use in conversion |
toArray | final public static String[] toArray(String s, String delim, boolean returnDelims)(Code) | | turn a string into a string array based upon a delimiter
Parameters: s - the string to convert Parameters: delim - the delimiters to use in conversion Parameters: returnDelimiters - if true, then delimiters are included in the array |
toDirectory | final public static String toDirectory(String filename)(Code) | | makes sure that a directory filename ends with the file separator.
eg: /usr/local/lib becomes /usr/local/lib/
|
toHTML | final public static String toHTML(String s)(Code) | | convert a string into an 'HTML-ready' string, handling special characters and newlines
|
toHTML | final public static String toHTML(String s, boolean includeBR)(Code) | | convert a string into an 'HTML-ready' string, handling special characters.
This will convert newlines to html breaks if specified
|
toList | final public static List toList(String s, String delim, List list)(Code) | | chop a string up into tokens based upon the delimiter and add
the tokens to a list
|
toList | final public static List toList(String s, String delim)(Code) | | turn a string into a list based upon a delimiter
|
toMap | final public static Map toMap(String s, String delim)(Code) | | turn a string into a map of param=value objects based upon a delimiter.
The string should be something like: "a=100,b=hello,c=a203" where the delimiter
is obviously ","
|
toMap | final public static void toMap(Map m, String s, String delim)(Code) | | turn a string into a map of param=value objects based upon a delimiter and
using the specified map object for the result
|
unescape | final public static String unescape(String s)(Code) | | take a string that contains escaped values \\n \\t \\r and returns it with
the actual escape codes (\n, \t, \r)
|
|
|