I am writing a script that gets its data from a text file and separates it into several strings. Here is my problem, I need a way to get individual items from a line of the format:
GreenThings: grass, tree leaves, yellow+blue
I tried getting them via the “word” class but items like the last two get separated.
I read somewhere about a “delimiter” command that I thought might help divide the line by commas but can’t seem to figure out the syntax.
Any help would be much appreciated
thanks
The following will do what you want. But be warned…using comma’s as delimiters can be a big mistake, unless you are certain that there is no way for a comma to end up in your data source.
set rawData to "GreenThings: grass, tree leaves, yellow+blue"
set olDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set {rawItem1, rawItem2, rawItem3} to text items of rawData
-- OR --
set listOfRawItems to text items of rawData
set AppleScript's text item delimiters to olDel
For flat-file databases, you should get into the habit of using rarely-used characters for delimiters to avoid future problems. I prefer the pipe “|” symbol. Imagine if you tried to parse the string…