parsing text containing hyphens

Hi – this is likely an easy question for the experts out there…

Let’s say I have
set myString to “My phone number is 555-1212”

I’d like to write a command that will result in the list {“My”, “phone”, “number”, “is”, “555-1212”}

I’m discovering that “words of myString” splits the phone number at the hyphen. Is there a way to parse the string so that hyphens aren’t used as word delimiters? I thought that just setting the text delimiter to " " might work, but no luck there.

One way that seems like it would work is to first replace hyphens with, for example “a-a”, then parse the string, then replace “a-a” with the hyphen again. Is there an easier way? Thanks!

Hi Mike,

changing text item delimiters does it

set myString to "My phone number is 555-1212"
set {TID, text item delimiters} to {text item delimiters, space}
set split to text items of myString
set text item delimiters to TID
split -- {"My", "phone", "number", "is", "555-1212"}

Excellent, thanks! I had tried to set the text item delimiter to {" "}, not space – maybe that was part of the problem. Also, didn’t reallize that you could use “text items” instead of “words” once you had set the text item delimiter.

At any rate, this works great, thanks!

space or {" "} does exactly the same thing.
Text items and words are different things.
Text items specify the part(s) of the string, which are separated by the current text item delimiter
words specify the part(s) of the string which are separated by space or one of these characters: ! \ " ( ) ’ : ; ? [ ] { } « » " " ˜ ’ -
and there are some special rules using charcters like & * + > < etc.