• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Removing leading and railing blanks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Removing leading and railing blanks
      • From: Michael Terry <email@hidden>
References: 
 >Re: Removing leading and railing blanks (From: Jeffrey Mattox <email@hidden>)

  • Prev by Date: Re: settle! was Re: Scripting Mail:get selection
  • Next by Date: Re: Some date math
  • Previous by thread: Re: Removing leading and railing blanks
  • Next by thread: Re: Removing leading and railing blanks
  • Index(es):
    • Date
    • Thread