On Jul 25, 2011, at 1:10 PM, 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.
Here's how I do that ...
repeat until (offset of (space & space) in subjectText) = 0 -- replace multiple spaces with single space
set AppleScript's text item delimiters to {space & space}
set wordList to (text items of subjectText) as list
set AppleScript's text item delimiters to {space}
set subjectText to wordList as text
end repeat
if ((length of subjectText) = 0) or (subjectText = space) then return "[no subject]"
if (first character of subjectText) is space then -- remove leading space
set subjectText to (text 2 thru -1 of subjectText)
end if
if (length of subjectText) > maxNameLen then
set subjectText to (text 1 thru maxNameLen of subjectText)
end if
if (last character of subjectText) is space then -- remove trailing space
set subjectText to (text 1 thru -2 of subjectText)
end if
return subjectText
I know it looks like it might be slow, but I think it's actually fast.