• 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 space chars from start of line
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trim space chars from start of line


  • Subject: Re: Trim space chars from start of line
  • From: "Zavatone, Alex" <email@hidden>
  • Date: Mon, 25 Jul 2011 13:40:16 -0700
  • Acceptlanguage: en-US
  • Thread-topic: Trim space chars from start of line

Your script is tied for the lead in speed at 19 seconds.  

This fixes if the whole line is spaces:

on MSTrimSpacesFromStartOfLine(myText)
if length of myText > 1 then
repeat
-- display dialog myText
if character 1 of myText is " " then
if the length of myText > 1 then
set myText to text 2 through end of myText
else
set myText to ""
return myText
end if
else
return myText
exit repeat
end if
end repeat
end if
end MSTrimSpacesFromStartOfLine


On Jul 25, 2011, at 3:23 PM, Michelle Steiner wrote:

Hey there, on Mon Jul 25 18:10:30 2011, Zavatone, Alex wrote the following interesting missive:

Hi.  I've got a little not so elegant script to trim spaces from the beginning of a line.  It handles if the whole line is full of spaces, but I was wondering if anyone out there has anything faster and is willing to share.

set source to "          1234               r"
set trimmed to TrimSpacesFromStartOfLine(source)

on TrimSpacesFromStartOfLine(myText)
if length of myText > 1 then
repeat
display dialog myText
if character 1 of myText is " " then
set myText to text 2 through end of myText
else
return myText
exit repeat
end if
end repeat
end if
end TrimSpacesFromStartOfLine
trimmed

-- 
"Better Plan B than plan d & c."


<ATT00001..txt>

This email message and any attachments are for the sole use of the intended recipient(s) and may contain information that is proprietary to U.S. Foodservice, Inc and/or its subsidiaries or otherwise confidential or legally privileged. If you have received this message in error, please notify the sender by reply, and delete all copies of this message and any attachments. If you are the intended recipient you may use the information contained in this message and any files attached to this message only as authorized by U.S. Foodservice. Files attached to this message may only be transmitted using secure systems and appropriate means of encryption, and must be secured using the same level password and security protection with which the file was provided to you. Any unauthorized use, dissemination or disclosure of this message or it's attachments is strictly prohibited.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Trim space chars from start of line (From: "Zavatone, Alex" <email@hidden>)
 >Re: Trim space chars from start of line (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: Trim space chars from start of line
  • Next by Date: Re: Trim space chars from start of line
  • Previous by thread: Re: Trim space chars from start of line
  • Next by thread: Re: Trim space chars from start of line
  • Index(es):
    • Date
    • Thread