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: Shane Stanley <email@hidden>
- Date: Tue, 26 Jul 2011 16:11:31 +1000
- Thread-topic: Trim space chars from start of line
Title: Re: Trim space chars from start of line
Too late for another entry?
This use AppleScriptObjC, and by using an array and an enumerator, it gets around the slowness of AS's handling of long lists. My old PowerBook suggests a time of about 0.25 secs. Oh, and it’s stripping trailing spaces (and tabs) too.
-- build string of 1000 paragraphs
set x to " The cat sat on the mat "
set y to x
repeat 999 times
set y to y & return & x
end repeat
log "start"
-- get white space character set (space and tab)
set whiteSpace to current application's NSCharacterSet's whitespaceCharacterSet()
-- make an array of paragraphs
set thePars to current application's NSArray's arrayWithArray_(paragraphs of y)
-- make new mutable array to add stripped pars to
set newArray to current application's NSMutableArray's arrayWithCapacity_(1000)
-- get an enumerator for the array
set theEnumerator to thePars's objectEnumerator()
-- loop
repeat
-- get a paragraph
set onePar to (theEnumerator's nextObject())
-- if it's missing value, we're at the end of the array
if onePar = missing value then exit repeat
-- strip par and add to new array
tell newArray to addObject_(onePar's stringByTrimmingCharactersInSet_(whiteSpace))
end repeat
--make string from array
set theResult to (newArray's componentsJoinedByString_(return)) as text
log "end"
--
Shane Stanley <email@hidden>
'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/>
_______________________________________________
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