Delete Characters From Variable?

Posted on
Thu Apr 26, 2012 7:48 am
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Delete Characters From Variable?

I'll begin with a Doh!, because I know this should be easy...but it just escapes me.

I have a variable that I need to remove the "+1" from,
e.g. "+1 (406) 555-5555" to "(406) 555-5555"

Any help greatly appreciated!

Thanks,

Carl

Posted on
Thu Apr 26, 2012 2:30 pm
jay (support) offline
Site Admin
User avatar
Posts: 18221
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Delete Characters From Variable?

Code: Select all
set longPhoneNumber to "+1 (406) 555-5555"
set AppleScript's text item delimiters to " "
set shortPhoneNumber to (text items 2 thru 3 of longPhoneNumber as string)


Results in "(406) 555-5555".

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Apr 26, 2012 4:06 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Delete Characters From Variable?

Or...
Code: Select all
set longPhoneNumber to "+1 (406) 555-5555"
set shortPhoneNumber to do shell script ("echo \"" & longPhoneNumber & "\" |tr -d \"+\"")


... the shell is your friend (and about as easy to understand as a spouse).

Posted on
Thu Apr 26, 2012 4:12 pm
jay (support) offline
Site Admin
User avatar
Posts: 18221
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Delete Characters From Variable?

berkinet wrote:
the shell is your friend


Sometimes not so much... :D

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Apr 27, 2012 12:06 am
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Delete Characters From Variable?

jay (support) wrote:
berkinet wrote:
the shell is your friend


Don't know about the shell, but this forum certainly is!

Many thanks, works perfectly. I incorporated it into the script that Dialectic
runs to send Indigo the CID info, now without the rather annoying +1
in the number.

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 12 guests