Split

From Xojo Documentation
Jump to: navigation, search
Method

Creates a one-dimensional array from the String passed.


Syntax

result=Split(source [,delimiter])
OR
source.Split([delimiter])

Part Type Description
result String array Array resulting from breaking source into elements using delimiter as the field delimiter.
source String Source string to be parsed into an array.
delimiter String Optional field delimiter used to parse Source into array elements. If delimiter is omitted, then a space is used as the delimiter.

Notes

Use the Split function to create a new String array from a list of elements (or fields) that are separated by a delimiter. If the optional parameter, delimiter, is not passed, a single space is assumed as the delimiter. If the delimiter is an empty string, the source string is split into characters.

Known Issues

According to Feedback Case 16302, Split may not work in all cases as documented here. For instance, if the application is running on a Japanese Windows system, Split returns an empty array when splitting by an empty string. To be on the safe side until this has been fixed, you should access the characters in a string using the Mid function instead, e.g. like this:

charAtX = theString.MidB(x, 1)

Examples

The first example specifies the comma delimiter and the second example uses the default delimiter. They place each field into an array element, producing a three-element array. The last example parses the string into individual characters.

Dim anArray(-1) as String
anArray=Split("Adam,Aardvark,Accountant",",")
anArray=Split("Adam Aardvark Accountant")
anArray=Split("Adam","")
//First two using the alternate syntax:
Dim s as String
s="Adam,Aardvark,Accountant"
anArray=s.Split(",") //produces 3-element array
anArray=s.Split("") //produces array of individual characters, but should be avoided (see Bug note above)


See Also

String data type; Dim statement; Array, Join, NthField, Ubound functions; Append, IndexOf, Insert, Pop, Redim, Remove, Shuffle, Sort, Sortwith methods; ParamArray keyword.

Personal tools
Namespaces

Variants
Actions
Main
Documentation
Community
Toolbox
Help