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: Steve Mills <email@hidden>
- Date: Mon, 25 Jul 2011 15:41:09 -0500
On Jul 25, 2011, at 15:20:05, email@hidden wrote:
> on TrimSpacesFromStartOfLine(myText)
>
> repeat while (first character of myText = " ")
> if myText > space then
> set myText to characters 2 through -1 of myText as string
> else
> set myText to ""
> exit repeat
> end if
> end repeat
>
> return myText
> end TrimSpacesFromStartOfLine
I haven't been following this thread closely, but from what I've seen, every script offered is copying most of the text over and over again. Wouldn't it be faster to count the leading spaces then move the text once? The answer is yes. The above script took 0.03 seconds on a small hunk of text with 171 leading spaces, while my script below took 0.00 seconds.
on TrimLeadingSpaces(t)
set num to length of t
set i to 1
repeat while i ≤ num and character i of t is " "
set i to i + 1
end repeat
if (i - 1) is num then
return ""
else
return text (i) thru -1 of t
end if
end TrimLeadingSpaces
--
Steve Mills
Drummer, Mac geek
_______________________________________________
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