Package io.milton.common
Class StringSplitUtils
java.lang.Object
io.milton.common.StringSplitUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringReplacealloccurencesofasubstringwithinastringwith anotherstring.static String[]Splits aStringat the first instance of the delimiter.static MapsplitEachArrayElementAndCreateMap(String[] array, String delimiter, String removeCharacters) Takes an array ofStrings, and for each element removes any instances ofremoveCharacter, and splits the element based on thedelimiter.static String[]splitIgnoringQuotes(String str, char separatorChar) Splits a given string on the given separator character, skips the contents of quoted substrings when looking for separators.static StringsubstringAfterLast(String str, String separator) static StringsubstringBeforeLast(String str, String separator)
-
Method Details
-
split
Splits aStringat the first instance of the delimiter.Does not include the delimiter in the response.
- Parameters:
toSplit- the string to splitdelimiter- to split the string up with- Returns:
- a two element array with index 0 being before the delimiter, and index 1 being after the delimiter (neither element includes the delimiter)
- Throws:
IllegalArgumentException- if an argument was invalid
-
splitEachArrayElementAndCreateMap
public static Map splitEachArrayElementAndCreateMap(String[] array, String delimiter, String removeCharacters) Takes an array ofStrings, and for each element removes any instances ofremoveCharacter, and splits the element based on thedelimiter. AMapis then generated, with the left of the delimiter providing the key, and the right of the delimiter providing the value.Will trim both the key and value before adding to the
Map.- Parameters:
array- the array to processdelimiter- to split each element using (typically the equals symbol)removeCharacters- one or more characters to remove from each element prior to attempting the split operation (typically the quotation mark symbol) ornullif no removal should occur- Returns:
- a
Maprepresenting the array contents, ornullif the array to process was null or empty
-
replace
Replacealloccurencesofasubstringwithinastringwith anotherstring. -
substringBeforeLast
-
substringAfterLast
-
splitIgnoringQuotes
Splits a given string on the given separator character, skips the contents of quoted substrings when looking for separators. Introduced for use in DigestProcessingFilter (see SEC-506). This was copied and modified from commons-lang StringUtils
-