• 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: Tidying a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tidying a string


  • Subject: Re: Tidying a string
  • From: kai <email@hidden>
  • Date: Thu, 28 Apr 2005 20:48:47 +0100


On Thu, 28 Apr 2005 17:42:34 +0100, pete boardman wrote:

Given a text string such as " foo bar foo bar foo bar ", where there are a variable number of spaces between each word, and 0 or more spaces at both start and end, I'd like to strip all unnecessary spaces and get "foo bar foo bar foo bar". I can't seem to get text delimiters working to do this. Is there an easy and fast > way?

to trimSpaces from t set d to text item delimiters set text item delimiters to " " repeat while (count t's text items) > 1 set t to t's text items set text item delimiters to space set t to t as string set text item delimiters to " " end repeat set text item delimiters to d if t starts with space then set t to t's text 2 thru -1 if t ends with space then set t to t's text 1 thru -2 t end trimSpaces

trimSpaces from "   foo     bar, foo   bar  (foo  bar).   "
--> "foo bar, foo bar (foo bar)."

---
kai

_______________________________________________
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


  • Prev by Date: sync APPLE WORKS DATABASE AND PALM os database
  • Next by Date: Re: Tidying a string
  • Previous by thread: Re: Tidying a string
  • Next by thread: RE: mail via terminal goes to internal address but not to externaladdress
  • Index(es):
    • Date
    • Thread