Re: How best to extract digits from a string?
Re: How best to extract digits from a string?
- Subject: Re: How best to extract digits from a string?
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 28 Apr 2001 09:51:00 -0700
On 4/28/01 9:27 AM, "Arthur J Knapp" <email@hidden> wrote:
>
> 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"
>
Not if you're "internationally" oriented. The standard format for phone
numbers in Europe - and I've seen it occasionally in the U.S too - is to
precede the country code by a "+" or in some countries even two of them. I
think that's to indicate specifically that you're using international
format, which in some countries, like the UK, means that you drop the
internal "0" from the area code which people dial within the country. So a
London phone number which is
(0207) 624 2060
within Britain, is printed on stationery and recorded in Address Books of
people elsewhere in Europe this way:
+44 207 624 2060
So:
set input to "+44 207 624 2060"
set phWds to every word of input
repeat while item 1 of phWds = "+"
set phWds to rest of phWds
end repeat
set output to "" & phWds
-- > "442076242060"
That should still be pretty fast.
--
Paul Berkowitz