splitting a string

Hello,

How can i split a string like this “Some Lable Name, Cat# 12345” into lableName and catNumber by splitting on ", " (comma space) delimeter?
in shell i would do something like:

lableName=echo $string | awk -F,\ '{print $1}'
catNumber=echo $string | awk -F,\ '{print $NF}'

I do no see any kind of split function in AppleScript, am i missing something?

Today i picked up a book “ApppleScrpt Programming for the absolute beginner” because it was the only AppleScript book the book store had.
Looks like i should’ve driven to another store and got me a copy of AppleScript book from O’Reilly…

thanks
i

http://bbs.applescript.net/viewtopic.php?pid=65331#p65331

thank you so much!

/me makes a note of the search function :slight_smile:

Ok, i must me missing something here, and could not figure out what.

My little test script works just fine:


on splitText(delimiter, someText)
	global lableName
	global catNumber
	set prevTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to delimiter
	set lableName to first text item of someText
	set catNumber to last text item of someText
	set AppleScript's text item delimiters to prevTIDs
	return lableName & catNumber
end splitText

set myString to "Aroma, AROMA 046"
splitText(", ", myString)

display dialog lableName & tab & catNumber

this works, but when i add thise little splitText() subroutine to an iTunes sctipt and call splitText() later, i get an error:

In that script i have EXACT SAME subroutine and call it later in the script:


set myComment to comment of theTrack
splitText(",", myComment)

if newLocation contains "[lable name]" then tell me to set newLocation to replaceText(newLocation, "[lable name]", lableName)
if newLocation contains "[cat number]" then tell me to set newLocation to replaceText(newLocation, "[cat number]", catNumber)

Script Utility Event Log shows this:

As you can see myComment variable gets passed to the splitText() correctly, but for the life of me i could not figure out why it does not work in this script,
but works fine on its own…

thanks in advance
i

Hi,

iTunes has no idea what a handler is,
within an application tell block the keyword my is required to target AppleScript itself

my splitText(", ", myString)

problem solved! thank you so much!!!

Scope of Subroutine Calls in Tell Statements