Re: Trim space chars from start of line
Re: Trim space chars from start of line
- Subject: Re: Trim space chars from start of line
- From: Stan Cleveland <email@hidden>
- Date: Mon, 25 Jul 2011 13:18:51 -0700
On Jul 25, 2011, at 12:59 PM, Zavatone, Alex wrote:
> Still need to speed this up, but I'll live with it for now. Thanks all.
Hi Alex,
If you can live with losing all whitespace (tabs, returns, newlines, etc.) AND you can live with a shell call, this handler might be worth a look:
on stripLeadingWhiteSpace(str)
-- escape single quotes, if present
if theText contains "'" then -- apostrophe
set oldTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to "'" -- apostrophe
set textParts to text items of theText
set AppleScript's text item delimiters to "\\'" -- escaped backslash, apostrophe
set theText to textParts as text
set AppleScript's text item delimiters to oldTIDs
end if
-- removes leading whitespace
do shell script ("ruby -e \"puts('" & str & "'.lstrip)\"")
end stripLeadingWhiteSpace
Stan C.
_______________________________________________
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