Re: Tidying a string
Re: Tidying a string
- Subject: Re: Tidying a string
- From: "Marc Rubin" <email@hidden>
- Date: Thu, 28 Apr 2005 13:19:50 -0400
> I'd like to strip all
> unnecessary spaces and get "foo bar foo bar foo bar".
is it considered 'vanilla' enough to script the shell to use grep to
replace:
"^ +" with ""
" +$" with "".
" +" with " "
Martin Orpen <email@hidden>
Sent by: To: AppleScript
applescript-users-bounces+mrubin=medimedia.com@list <email@hidden>
s.apple.com cc:
Subject: Re: Tidying a string
04/28/2005 01:04 PM
on 28/4/05 17:56, Michelle Steiner at email@hidden wrote:
> set foo to " foo bar foo bar foo bar "
> set text item delimiters to space
> set foo to text items of foo
> set foobar to {}
> repeat with i from 1 to count of foo
> if item i of foo is not "" then copy item i of foo to end of foobar
> end repeat
> foobar
> set foobar to foobar as string
> set text item delimiters to ""
> set foo to foobar
Or the lazier:
set t to " foo bar foo bar foo bar "
set AppleScript's text item delimiters to " "
log words of t as string
set AppleScript's text item delimiters to ""
--> (*foo bar foo bar foo bar*)
--
Martin Orpen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden