How can I split a string?

The term split is commonly used in other programming languages to define the way to convert a text into a list of texts (or “array”, “vector”, etc., in other languages).

Plain AppleScript doesn’t have a built-in “split” command, but you can use text item delimiters to do the same task:

split("This is a text", space)
--> {"This", "is", "a", "text"}

to split(someText, delimiter)
	set AppleScript's text item delimiters to delimiter
	set someText to someText's text items
	set AppleScript's text item delimiters to {""} --> restore delimiters to default value
	return someText
end split

More info about TIDs (Text Item Delimiters), here.

Also, there are some scripting additions which will allow you a more direct way for a “split” function, such as Acme Script Widgets’ “tokenize” command:

tokenize "This is a text" with delimiters {"a"}
--> {"This is ", " text"}