Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Ethereal11

macrumors newbie
Original poster
Jan 19, 2009
3
0
So, I'm getting into Applescripts and have come to a road block in trying to extract a string of numbers from a variable. My variables read like so..

"blah blah blah XXX-XX-XXXXXX-XX-X yadda yadda"

How can I go about setting XXX-XX-XXXXXX-XX-X as a new variable with the other verbiage floating around it? I need to maintain the hyphens in the resulting variable.

TIA!!
 
Try this

Perhaps not the best or most elegant solution but it works.

Code:
set the_String to "blah blah blah 123-45-678925-78-9 yadda yadda"
try
	set oldDelims to AppleScript's text item delimiters -- save their current state
	set AppleScript's text item delimiters to {" "} -- declare new delimiters
	-- do script steps here
	set these_items to the text items of the_String
	-- the result of the these_items is a list:
	-- {"blah", "blah", "blah", "123-45-678925-78-9", "yadda", "yadda"}
	set AppleScript's text item delimiters to oldDelims -- restore them
on error
	set AppleScript's text item delimiters to oldDelims -- restore them in case something went wrong
end try
-- we take the 4th item in the list
--the result of the_new_String will be : "123-45-678925-78-9"
set the_new_String to (item 4 of these_items)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.