StrSplitToArray

See Also: Array Functions, Array Variable Assignments, String Functions, Working with Arrays, StrSplitToArray

Purpose

Splits the contents of a single String into the elements of a String array.

Return Type

Array

Syntax

StrSplitToArray( {StringVar}, {Delimiter} )

Where:

What it Does

StrSplitToArray separates sub-strings from a singles string , separated by the specified delimiter, into elements in a String array.

Example

This sample separates the sub-strings (in this case 4 names), separated by commas, into the first 4 elements in String array Flintstones. The result will be:

Flinstones[0]: Fred
Flinstones[1]: Wilma
Flinstones[2]: Betty
Flinstones[3]: Barney

Procedure Test

    String[] Flintstones

    String sNames

    

    Move "Fred,Wilma,Betty,Barney" to sNames

    

    Move (StrSplitToArray (sNames, ",")) to Flintstones

End_Procedure

Note that the resulting String array elements are in the same order as the sub-strings in the source string. If you would like the resulting String array to be sorted, you need to sort the array (using SortArray) after calling StrSplitToArray.

The result will be:

Flinstones[0]: Barney
Flinstones[1]: Betty
Flinstones[2]: Fred
Flinstones[3]: Wilma

Procedure Test

    String[] Flintstones

    String sNames

    

    Move "Fred,Wilma,Betty,Barney" to sNames

    

    Move (StrSplitToArray (sNames, ",")) to Flintstones

    Move (SortArray(Flintstones)) to Flintstones

End_Procedure

 

Array Dimensions

You can use static arrays, but if your source string {StringVar} contains more elements than the target array, it will trigger an errror:

Path\ProgramName.exe

Illegal Datatype Conversion. Incompatible size of 0. dimension - Cannot convert array of 'STRING[]' to array of 'STRING[3]'

Error: 4381

We recommend using dynamic arrays instead.