• 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: Christopher Stone <email@hidden>
  • Date: Mon, 25 Jul 2011 14:20:11 -0500

On Jul 25, 2011, at 13:10, Zavatone, Alex wrote:
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.
______________________________________________________________________

Hey Alex,

------------------------------------------------------------------------------------------------
on trimLeadingWhiteSpace(str)
set cmd to "sed -nE 's/^[ ]*//p'<<<" & quoted form of str
do shell script cmd
return result
end trimLeadingWhiteSpace
------------------------------------------------------------------------------------------------

set str to "    Some Text 1
    Some Text 2
    Some Text 3
    Some Text 4
    Some Text 5
    Some Text 6

     

     

     




Some Text 7
"

trimLeadingWhiteSpace(str)

------------------------------------------------------------------------------------------------

This is pretty fast.

Personally I'd use the Satimage.osax's regular expressions for speed and flexibility.

--
Best Regards,
Chris

 _______________________________________________
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

  • Follow-Ups:
    • Re: Trim space chars from start of line
      • From: "Zavatone, Alex" <email@hidden>
References: 
 >Trim space chars from start of line (From: "Zavatone, Alex" <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