Skip to content

StringUtils.splitByWholeSeparatorPreserveAllTokens

Signature: StringUtils.splitByWholeSeparatorPreserveAllTokens(inputString, separator, max*)

Returns: String[] tokens - an array of parsed Strings, or null if inputString is null

Splits the provided inputString into an array, using the separator specified. The separator is not included in the returned String[]. Adjacent separators are treated as separators for empty tokens. A null inputString returns null.

Parameters

Type Name Description Default
String inputString the text to split
String separator the string used as the delimiters, null splits on whitespace
Integer max* (optional) the maximum number of elements to include in the array. A zero or negative value implies no limit. 0

Example

// Split on whitespace (default when separator is null)
var splitArray = StringUtils.splitByWholeSeparatorPreserveAllTokens(
    'you and me   and max!',
    null
);
// Result: ["you","and","me","","","and","max!"]

// Split on a literal separator and preserve empty tokens
splitArray = StringUtils.splitByWholeSeparatorPreserveAllTokens(
    'The,,quick,brown,,fox',
    ','
);
// Result: ["The","","quick","brown","","fox"]