• 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: Thu, 28 Jul 2011 11:01:39 -0700
  • Acceptlanguage: en-US
  • Thread-topic: Trim space chars from start of line

I think you're correct!

It was your 4 solutions that showed me that it was my loop that was wasting all the time.

However, at the time, I was still thinking in "single line mode" and didn't think to assume that your solution would remove the leading spaces from al lines in a text string, not just the first.

You should see my test applescript, with each person's submitted solution as a handler preceded with their initials.

You have your own section in my file Mark :)

On Jul 28, 2011, at 12:48 PM, Mark J Reed wrote:

Ya know, that looks an awful lot like one of the solutions I posted.  Just saying. :)

Also you can get rid of the -n and the /p - they cancel each other out in this case.

sed 's/^  *//'

Sed reads in its input a line at a time, runs the given transformations on each line, and prints out the result.

s/^. *// says to substitute the empty string for any number of spaces at the start of the line.

s/old/new/ -> replace first occurrence of "old" on the line with "new"

Old is actually a pattern, not a string; some characters are special:

^ matches the start of the line

space isn't special - it just matches itself

space *  matches any number of spaces 

Nothing between the middle and last / means the text that matches is replaced with nothing - that is, removed.



Sent from my iPhone

On Jul 28, 2011, at 13:35, "Zavatone, Alex" <email@hidden> wrote:

You sir, are a benefit to humanity.

Now, how can I find out why that does what that does?  

Any good guides to get started?

Danke.

On Jul 25, 2011, at 2:20 PM, Christopher Stone wrote:

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

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: Christopher Stone <email@hidden>)
 >Re: Trim space chars from start of line (From: "Zavatone, Alex" <email@hidden>)
 >Re: Trim space chars from start of line (From: Mark J Reed <email@hidden>)

  • Prev by Date: Re: Trim space chars from start of line
  • Next by Date: open alias discrepancy in OS X Lion?
  • 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