public class StringHelper extends Object
Constructor and Description |
---|
StringHelper() |
Modifier and Type | Method and Description |
---|---|
static int |
countOccurances(String content,
String occurs)
Returns the number of times a particular String occurs in another String.
|
static String[] |
delimitedToArray(String str,
String delimiter,
boolean keepEmpties)
Convert a string that has delimited values (say comma delimited) in a
String[].
|
static Map<String,String> |
delimitedToMap(String allNameValuePairs,
String listDelimiter,
String nameValueSeparator)
Parses out a list of Name Value pairs that are delimited together.
|
static boolean |
isNull(String value)
Return true if the value is null or an empty string.
|
static HashMap<String,String> |
parseNameQuotedValue(String tag)
parses a String of the form name1='value1' name2='value2'.
|
static String |
replaceString(String source,
String match,
String replace)
This method takes a String and will replace all occurrences of the match
String with that of the replace String.
|
static String |
replaceString(String source,
String match,
String replace,
int additionalSize,
int startPos,
int endPos)
Additionally specify the additionalSize to add to the buffer.
|
static String |
replaceStringMulti(String source,
String[] match,
String replace)
A search and replace with multiple matching strings.
|
static String |
replaceStringMulti(String source,
String[] match,
String replace,
int additionalSize,
int startPos,
int endPos)
Additionally specify an additional size estimate for the buffer plus start
and end positions.
|
static String[] |
splitNames(String names)
Splits at any whitespace "," or ";" and trims the result.
|
static String |
trimFront(String source,
String trim)
Trims off recurring strings from the front of a string.
|
public StringHelper()
public static HashMap<String,String> parseNameQuotedValue(String tag) throws RuntimeException
RuntimeException
public static int countOccurances(String content, String occurs)
public static Map<String,String> delimitedToMap(String allNameValuePairs, String listDelimiter, String nameValueSeparator)
allNameValuePairs
- the entire string to be parsed.listDelimiter
- (typically ';') the delimited between the listnameValueSeparator
- (typically '=') the separator between the name and valuepublic static String trimFront(String source, String trim)
source
- the source stringtrim
- the string to trim off the frontpublic static boolean isNull(String value)
public static String[] delimitedToArray(String str, String delimiter, boolean keepEmpties)
e.g. "alpha,beta,,theta"
With keepEmpties true, this results in a String[] of size 4 with the third
one having a String of 0 length. With keepEmpties false, this results in a
String[] of size 3.
e.g. ",alpha,beta,,theta,"
With keepEmpties true, this results in a String[] of size 6 with the
1st,4th and 6th one having a String of 0 length. With keepEmpties false,
this results in a String[] of size 3.
public static String replaceString(String source, String match, String replace)
source
- the source stringmatch
- the string used to find a matchreplace
- the string used to replace match withpublic static String replaceString(String source, String match, String replace, int additionalSize, int startPos, int endPos)
public static String replaceStringMulti(String source, String[] match, String replace)
Useful when converting CRNL CR and NL all to a BR tag for example.
String[] multi = { "\r\n", "\r", "\n" };
content = StringHelper.replaceStringMulti(content, multi, "<br/>");
public static String replaceStringMulti(String source, String[] match, String replace, int additionalSize, int startPos, int endPos)
The start and end positions can limit the search and replace. Otherwise these default to startPos = 0 and endPos = source.length().
public static String[] splitNames(String names)
Copyright © 2019. All rights reserved.