Re: Removing leading and railing blanks
Re: Removing leading and railing blanks
- Subject: Re: Removing leading and railing blanks
- From: Michael Terry <email@hidden>
- Date: Tue, 25 Feb 2003 17:07:49 -0800
On 2/25/03 12:46 AM, "Jeffrey Mattox" <email@hidden> wrote:
>
At 11:04 PM -0800 2/24/03, Michael Terry wrote:
>
> On 2/24/03 10:51 PM, "Jeffrey Mattox" <email@hidden> wrote:
>
>
>
>> What's the most efficient way to remove leading and trailing blanks
>
>> from a string?
>
>
>
> set AppleScript's text item delimiters to space
>
> words of theString as string
>
>
Well, it has to work with arbitrary strings. That removes leading
>
and trailing spaces, but it also mangles some strings. To wit:
>
>
set theString to " date '+%B %e, %G' "
>
set AppleScript's text item delimiters to space
>
words of theString as string
>
-- "date + % B % e % G"
Alright, now. It can be efficient or it can work: Pick one. Anyway, this one
scales well.
set a to " date '+%B %e, %G' "
set b to "date '+%B %e, %G'"
chomp(a)
result = b
--> true
on chomp(str)
set n to str's {text 1 thru word 1, text -1 thru word -1}
set AppleScript's text item delimiters to space
set n to {n's front's text items, n's end's text items}
set AppleScript's text item delimiters to return
set n to {n's front as string, n's end as string}
set n to {paragraphs of n's front, paragraphs of n's end}
set n to {n's front's rest's length, n's end's rest's length}
text ((n's front) + 1) thru -((n's end) + 1) of str
end chomp
Mike
_______________________________________________
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.