You are not logged in.
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
Offline
Take your pick ...
Applescript:
set xxx to "+1 (406) 555-5555"
if xxx contains "+1 " then
set yyy to characters 4 thru -1 of xxx as string
end if
set zzz to do shell script "echo " & quoted form of xxx & " | sed 's/+1 //'"
if xxx contains "+1 " then
set {Astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "+1 "}
set aaa to text items 2 thru -1 of xxx as string
set AppleScript's text item delimiters to Astid
end if
return {aaa, yyy, zzz}
Last edited by adayzdone (2012-04-26 02:23:16 pm)
Offline
Hi.
adayzdone wrote:
Applescript:
set yyy to characters 4 thru -1 of xxx as string
This creates a list of characters and then coerces it to string using the current value of AppleScript's text item delimiters. For efficiency and safety, the following would be preferable, as it extracts the subtext directly:
Applescript:
set yyy to text 4 thru -1 of xxx
Similarly …
Applescript:
set aaa to text items 2 thru -1 of xxx as string
… could be more efficiently rendered:
Applescript:
set aaa to text from text item 2 to -1 of xxx
Offline
Hi Nigel,
Good tips, especially the "text from". Thanks!
Offline
Hello Nigel
Am'I dreaming ?
As far as I remember,
Applescript:
set xxx to "+1 (406) 555-5555"
set aaa to text from text item 2 to -1 of xxx
remove only the character "+"
To remove "+1", it must be
set aaa to text from text item 3 to -1 of xxx
and, if we want to remove "+1 " which is what was done in the other examples, it must be :
set aaa to text from text item 4 to -1 of xxx
Yvan KOENIG (VALLAURIS, France) vendredi 27 avril 2012 19:15:41
Offline
Yes. I was referring to adayzdone's suggestions in post #2 and had trimmed the quotes and my reply to focus on the particular lines.
Last edited by Nigel Garvey (2012-04-27 03:49:11 pm)
Offline
Thanks
Clearly I misunderstood the contents of Nigel's message.
Yvan KOENIG (VALLAURIS, France) vendredi 27 avril 2012 20:56:01
Offline