• 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: Trim?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trim?


  • Subject: Re: Trim?
  • From: Nigel Garvey <email@hidden>
  • Date: Sat, 3 Aug 2002 14:24:10 +0100

John Delacour wrote on Sat, 3 Aug 2002 02:35:46 +0100:

>At 2:37 pm -0700 2/8/02, email@hidden wrote:
>
>>Does anyone know if there's a simple way to trim white space off of a
>>string, or should I just loop through it and take them out myself?
>
>set s to " This is > a string "
>set AppleScript's text item delimiters to {space}
>set s to "" & words of s
>set AppleScript's text item delimiters to {""}
>return s

Or, of course:

set s to " This is > a string "
return text from word 1 to word -1 of s

My version doesn't tidy up multiple spaces between words, whereas John's
does. However, his might also insert spaces where none were previously -
eg. around the "@" in an e-mail address. Both scripts, unfortunately, zap
punctuation as well as white space.

The following effort covers all the eventualities, as far as I can see:

set s to " email@hidden 'This is a > string?' "

set AppleScript's text item delimiters to {space}
set l to s's text items
set AppleScript's text item delimiters to {""}

-- Prepend a space to every non-blank text item except the first
set started to false
repeat with thisItem in l
if (count thisItem) > 0 then
if started then
set thisItem's contents to (space & thisItem)
else
set started to true
end if
end if
end repeat

return l as string --> "email@hidden 'This is a > string?'"

NG
_______________________________________________
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: Trim?
      • From: Paul Skinner <email@hidden>
    • Re: Trim?
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: "+" and "-" are numbers.
  • Next by Date: Re: duplicate one file
  • Previous by thread: Re: Trim?
  • Next by thread: Re: Trim?
  • Index(es):
    • Date
    • Thread