Re: Address Book script contribution
Re: Address Book script contribution
- Subject: Re: Address Book script contribution
- From: has <email@hidden>
- Date: Wed, 5 Mar 2003 14:47:35 +0000
Matt Petrowsky wrote:
Since switching to Address Book I found that my collection of contacts
from over the years has every possible treatment of phone number
formatting.
So here is a nice script that will currently format your phone numbers
(10 digit US) into (xxx) xxx-xxxx format.
[snip]
Here's a couple improvements for your cleanNumber handler, extracting
digits by a more conventional method and getting substrings by 'text
x thru y' instead of TID-unsafe 'characters x thru y as string'. Use
as you like. HTH.
======================================================================
on stripNonDigits(str)
set newStr to ""
considering hyphens, punctuation and white space
repeat with charRef in str
if charRef's contents is in "1234567890" then
set newStr to newStr & charRef
end if
end repeat
end considering
return newStr
end stripNonDigits
on formatAsUSPhoneNumber(tenDigitString)
return "(" & text 1 thru 3 of tenDigitString & ") " & text 4 thru
[NO-BREAK]6 of tenDigitString & "-" & text 7 thru 10 of tenDigitString
end formatAsUSPhoneNumber
on cleanNumber(theString)
set rawPhoneNumber to stripNonDigits(theString)
if rawPhoneNumber's length is 10 then
return formatAsUSPhoneNumber(rawPhoneNumber)
else
return theString
end if
end cleanNumber
======================================================================
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.