• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How best to extract digits from a string?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How best to extract digits from a string?


  • Subject: Re: How best to extract digits from a string?
  • From: "Arthur J Knapp" <email@hidden>
  • Date: Sat, 28 Apr 2001 12:27:12 -0400

> Date: Fri, 27 Apr 2001 18:30:30 -0400
> Subject: Re: How best to extract digits from a string?
> From: Bill Cheeseman <email@hidden>

> Well, string operations still have to work as arrays/lists/vectors/something
> under the hood. But that's what I've found today, trying to better the
> efficiency of my original technique (with your enhancement) for extracting
> digits from a string. In my testing, concatenating strings remains a little
> less than 5% faster than Paul Berkowitz's technique using the "end of"
> syntax on a list. I haven't been able to find anything faster, at least for
> short input strings like phone numbers.
>
> I even tried a couple of tricks based on foreknowledge that the output
> string for an area code and telephone number has to be 10 characters long,
> but I couldn't find anything faster.

In the very specific case where the input is a phone number, (ie:
"(800) 555-1212", a string of numbers, hyphens, and parentheses),
this should do:

set input to "(800) 555-1212"
set output to "" & every word of input

-- > "8005551212"

At one time, it seems to me that AppleScript used to treat
a hyphen in front of a number as part of a word, ie:

set input to "abcd-1212"
set output to every word of input

-- > {"abcd", "-1212"}

but that no longer seems to be the case:

-- > {"abcd", "1212"}

In fact, I no longer trust the "word" reference in the way
that I use to. AppleScript's definition of what constitutes a
"word" seems to change with every new version.


Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden

Hey, check out:
http://www.vivaladata.com


  • Follow-Ups:
    • Re: How best to extract digits from a string?
      • From: Bill Cheeseman <email@hidden>
    • Re: How best to extract digits from a string?
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: Mike Mortin is out of the office.
  • Next by Date: Re: How best to extract digits from a string?
  • Previous by thread: Re: How best to extract digits from a string?
  • Next by thread: Re: How best to extract digits from a string?
  • Index(es):
    • Date
    • Thread