• 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: Mon, 25 Jul 2011 15:27:06 -0700
  • Acceptlanguage: en-US
  • Thread-topic: Trim space chars from start of line

OK.  I got it down to 2 seconds from 20.

Here's how.

My text is return delimited on a per line basis.

I added a return to the start of text or line 1 would be skipped.  Just have to remove that return after this operation.

It's the looping through all the lines that is so slow.  Since the lines may begin with a space, then every line really may start with a return and possibly spaces.  So if I do a find and replace with the string return & " " and replace that with just return, using the text item delimiters, I thought it would be faster.  And it sure is.

(*2 seconds*)

-- the new elven magic
set myCountAfter to 0 
set myCountBefore to 1
repeat while myCountBefore ≠ myCountAfter
set myCountBefore to length of myText
log myCountBefore
set myResult to SpecialFindAndReplace(myText, return & " ", return)
set myText to item 2 of myResult
set myCountAfter to item 1 of myResult
end repeat

-- found this somewhere and have been using it:
on SpecialFindAndReplace(TheString, tofind, toreplace)
set ditd to text item delimiters
set text item delimiters to tofind
set textItems to text items of TheString
set text item delimiters to toreplace
if (class of TheString is string) then
set res to textItems as string
else -- if (class of TheString is Unicode text) then
set res to textItems as Unicode text
end if
set text item delimiters to ditd
-- log res
return {length of res, res}
end SpecialFindAndReplace


Thanks to everyone for their help today.  Made my Monday.

Cheers, 
- Alex Zavatone

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

  • Follow-Ups:
    • Re: Trim space chars from start of line
      • From: Deivy Petrescu <email@hidden>
References: 
 >Trim space chars from start of line (From: "Zavatone, Alex" <email@hidden>)
 >Re: Trim space chars from start of line (From: Ron Hunsinger <email@hidden>)

  • Prev by Date: Re: Trim space chars from start of line
  • Next by Date: Re: Note on ASE scripting
  • 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