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: Bill Cheeseman <email@hidden>
- Date: Sat, 28 Apr 2001 14:11:38 -0400
on 4/28/01 12:27 PM, Arthur J Knapp at email@hidden wrote:
>
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"
Yes. But you're assuming that the input is known to be in a specific valid
telephone number format. If a user entered 800x555x1212, the "every word"
wouldn't extract digits and remove everything else.
To be sure, my original challenge did not specify any required error
checking, but the idea was to extract digits.
My real-life application extracts the first 7 or 10 digits from any string
(after doing some testing for valid phone number delimiters in the right
places), then uses the digits-only version to compare with other phone
numbers similarly extracted. This allows people to use a variety of input
formats while still permitting me to compare the actual digits for identity.
I also assume that any trailing text (e.g., "ext. 54", "x5", or "call
first") is OK and should be preserved.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
The AppleScript Sourcebook - www.AppleScriptSourcebook.com
Vermont Recipes - www.stepwise.com/Articles/VermontRecipes