Geert JM Vanderkelen

Splitting as string and joining a list using AppleScript

Splitting as string and joining a list using AppleScript

Two small helper AppleScript functions for joining a list and splitting a string given delimiter. Sure, quite an easy task, but it involves setting a global delimiter. Bit like FS in shell. I hope this helps a few folks out there starting out with AppleScript.

to joinList(aList, delimiter)
 set retVal to ""
 set prevDelimiter to AppleScript's text item delimiters
 set AppleScript's text item delimiters to delimiter
 set retVal to aList as string
 set AppleScript's text item delimiters to prevDelimiter
 return retVal
end joinList

to splitString(aString, delimiter)
 set retVal to {}
 set prevDelimiter to AppleScript's text item delimiters
 log delimiter
 set AppleScript's text item delimiters to {delimiter}
 set retVal to every text item of aString
 set AppleScript's text item delimiters to prevDelimiter
 return retVal
end splitString

Here a few lines showing how to use them:

set tmp to my splitString(oldAlias as text, ":")
set imgTags to my joinList(kwList, ",")

Again, no comments! Enjoy!

5 thoughts on “Splitting as string and joining a list using AppleScript

Leave a Reply

Your email address will not be published. Required fields are marked *

74 − = 70

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>