SplitText(text, separator, resultIndex, re)

Splits «text» into a list of substrings at each occurrence of «separator».

SplitText('Bob, Mary, Alice', ',') → ['Bob', 'Mary', 'Alice']

If «separator» is the empty text, "", it splits «text» into an array of individual characters.

SplitText('AbcdE', ") → ['A', 'b', 'c', 'd', 'E']

If «text» or «separator» are arrays, you need to specify the «resultIndex». See below for details.


SplitText(text, separator: text atom)


Text functions


SplitText('Al#Bob#Carl', '#') → ['Al', 'Bob', 'Carl']
SplitText('Al, Bob, Carl', ', ') → ['Al', 'Bob', 'Carl']

Case Sensitivity

When «separator» contains letters, the comparison is done in a case-sensitive fashion.

SplitText('abAcadAe', 'a') → [, 'bAc', 'dAe']
SplitText('abAcadAe', 'a', caseInsensitive: true) → [", 'b', 'c', 'd', 'e']

Regular Expressions

The «separator» parameter is interpreted as a regular expression when the optional re: true parameter is specified.

The following example splits on any word containing the letter h:

SplitText('Now is the time for all good men to come to the aid of their country', '\s*\w*h\w*\s*', re: 1)
→ ['Now is', 'time for all good menu to come to', 'aid of', 'country']

The above pattern identifies zero or more spaces '\s*', followed by zero or more letters '\w*', followed by the letter h, followed by zero or more letters, followed by zero or more spaces.

Using a subpattern, you can require the «separator» pattern to occur within a larger context, without including the larger context within the split point. For example, the following splits at decimal points, but only when they have a numeric digit on each side:

SplitText('17.5 19 1. .5 0.1111', '\d(\.)\d', re:1, subpattern: 1) → ['17', '5 19 1. .5 0', '1111']
SplitText('17.5 19 1. .5 0.1111', '(\d(?<a>\.)\d)|(?<a>\s+)', re: 1, subpattern:'a') → ['17', '5', '19', '1.', '.5', '0', '1111']

Splitting Arrays using «resultIndex»

If «text» or «separator» are arrays, you need to specify the «resultIndex». Otherwise, it will give an error that you are trying to combine two (or more) arrays with implicit indexes.

If the result index is longer than the number of items in the result, the remaining entries along the result index are set to Null. If the result index is shorter than the number of split items, the last item along result index will contain the remainder of the unsplit «text».

Index I := 1..3
Index J := 1..7
SplitText('One two three four five', ' ', resultIndex: I) →
I ▶
1 2 3
'One' 'two' 'three four five'
SplitText('One two three four five',' ', resultIndex: J) →
J ▶
1 2 3 4 5 6 7
'One' 'two' 'three' 'four' 'five' «null» «null»

In Analytica 4.1 or earlier, the optional «resultIndex» is not available. If you know that all text values in A will have the same number of elements, and index I has this same number of elements, you could use e.g.:

Var A[] := textArray do Array(I, SplitText(s, ' '))

When I is not guaranteed to have exactly the same number of items, the Array function will issue a warning, which can be ignored:

Var A[] := textArray do IgnoreWarnings(Array(I, SplitText(s, ' ')))

When I has more elements than the result of SplitText, the final elements in the result are padded with Null. When I has fewer elements, then only the first Size(I) split items are retained, e.g.:

Index I := 1..3
Array(I, SplitText('One two three four five',' ')) →
I ▶
1 2 3
'One' 'two' 'three'

See Also


You are not allowed to post comments.