Saturday, February 25, 2017

#1 2005-10-13 02:48:28 pm

From: MalasaƱa, Madrid
Registered: 2002-11-20
Posts: 2014

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"}



Board footer

Powered by FluxBB

[ Generated in 0.041 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)