View unanswered posts | View active topics It is currently Sun May 19, 2013 5:55 pm



Reply to topic  [ 5 posts ] 
 Delete Characters From Variable? 
Author Message

Joined: Nov 26, 2009
Posts: 923
Location: Kalispell, MT
Post 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


Thu Apr 26, 2012 7:48 am
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6642
Location: Austin, Texas
Post 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)
Image


Thu Apr 26, 2012 2:30 pm
Profile WWW
User avatar

Joined: Nov 18, 2008
Posts: 1720
Location: Berkeley, CA
Post 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).


Thu Apr 26, 2012 4:06 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6642
Location: Austin, Texas
Post Re: Delete Characters From Variable?
berkinet wrote:the shell is your friend


Sometimes not so much... :D

_________________
Jay (Indigo Support)
Image


Thu Apr 26, 2012 4:12 pm
Profile WWW

Joined: Nov 26, 2009
Posts: 923
Location: Kalispell, MT
Post 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


Fri Apr 27, 2012 12:06 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.