• 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: Paul Skinner <email@hidden>
  • Date: Tue, 25 Feb 2003 11:45:59 -0500

On Tuesday, February 25, 2003, at 01:51 AM, Jeffrey Mattox wrote:

What's the most efficient way to remove leading and trailing blanks from a string?

Jeff

Here's a solution for space runs and it handles this case...

RemoveSpaceRuns(" date '+%B %e, %G' ")
-->"date '+%B %e, %G'"

on RemoveSpaceRuns(inputText)
set space2 to space & space
set inputText to space & inputText & space
repeat while inputText contains space2
set AppleScript's text item delimiters to space2
set tempS to text items of inputText
set AppleScript's text item delimiters to space
set inputText to tempS as text
end repeat
set AppleScript's text item delimiters to ""
return text 2 thru -2 of inputText
end RemoveSpaceRuns

But you might want to just do...

RemoveEndingAndLeadingSpaces(" date '+%B %e, %G' ")
-->"date '+%B %e, %G'"

on RemoveEndingAndLeadingSpaces(inputText)
repeat with i from 1 to length of inputText
if item i of inputText is not " " then
copy i to beginText
exit repeat
end if
end repeat
repeat with i from length of inputText to 1 by -1
if item i of inputText is not " " then
copy i to endText
exit repeat
end if
end repeat
return text beginText thru endText of inputText
end RemoveEndingAndLeadingSpaces

Paul Skinner

If you ever reach total enlightenment while you're drinking a beer, I bet it makes beer shoot out your nose.
-Jack Handy Deep Thoughts _______________________________________________
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: Tim Mansour <email@hidden>
References: 
 >Removing leading and railing blanks (From: Jeffrey Mattox <email@hidden>)

  • Prev by Date: List item number
  • Next by Date: Print ? OSX -> 9.2wUSB HPjet
  • Previous by thread: Re: Removing leading and railing blanks
  • Next by thread: Re: Removing leading and railing blanks
  • Index(es):
    • Date
    • Thread