• 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?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trim?


  • Subject: Re: Trim?
  • From: Paul Skinner <email@hidden>
  • Date: Sat, 3 Aug 2002 18:53:58 -0400

On Saturday, August 3, 2002, at 03:01 PM, John Delacour wrote:

At 12:09 pm -0400 3/8/02, Paul Skinner wrote:

John Delacour wrote on Sat, 3 Aug 2002 02:35:46 +0100:

set s to " This is a string "
set AppleScript's text item delimiters to {space}
set s to "" & words of s
set AppleScript's text item delimiters to {""}
return s



You could skip some of the looping.

set inputText to " ...


What looping?

I was referring to Nigel's last method. While yours is expeditious, it's also overzealous. Adding spaces and removing punctuation.

set s to " email@hidden 'This is a > string?' "
set AppleScript's text item delimiters to {space}
set s to "" & words of s
set AppleScript's text item delimiters to {""}
return s
-->"fred @ boop.dot.com This is a > string"

His handles this but iterates on every text item of the text delimited by a space. My suggestion iterates over some percent of the characters to be removed.

given...set s to " email@hidden 'This is a > string?' "

NG's requires 14 iterations while mine takes 6. Over a larger text or text with greater numbers of spaces it becomes very significant. It requires contiguous white space of 160 characters before more than 21 iterations are required by my version.

I realize now that the version below is more efficient requiring only 15 loops to handle the 160 character run text...

set inputText to " email@hidden 'This is a > string?' "
cleanSpaces(inputText)
-->"email@hidden 'This is a > string?'"

on cleanSpaces(inputText)
set tag to "o#?"--opt shift k
set inputText to tag & inputText & tag
repeat while inputText contains " "
repeat with thesedelimiters in {{space & space, tag}, {tag & tag, tag}, {tag, space}}
set AppleScript's text item delimiters to item 1 of thesedelimiters
set tempS to text items of inputText
set AppleScript's text item delimiters to item 2 of thesedelimiters
set inputText to tempS as text
end repeat
end repeat
set AppleScript's text item delimiters to ""
return (characters 2 thru -2 of inputText) as text
end cleanSpaces

This version will clean up space runs in the text of this entire posting in 6 loops vs 433 for Nigel's.
--
Paul Skinner


tell JohnDelacour
tell JohnDelacour
display dialog "Welcome back!"
end
end
-->***** Scripting Eror ***** The variable JohnDelacour is not defined. : )
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
References: 
 >Re: Trim? (From: John Delacour <email@hidden>)

  • Prev by Date: Re: get default browser?
  • Next by Date: Re: Trim?
  • Previous by thread: Re: Trim?
  • Next by thread: Re: Trim?
  • Index(es):
    • Date
    • Thread