• 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: Remove extra spaces from a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Remove extra spaces from a string


  • Subject: Re: Remove extra spaces from a string
  • From: Paul Skinner <email@hidden>
  • Date: Mon, 9 Jun 2003 07:09:59 -0400

On Sunday, June 8, 2003, at 07:10 PM, Nigel Garvey wrote:

Paul Skinner wrote on Sun, 8 Jun 2003 07:32:51 -0400:

Quicker and neater than either.

set fileData to {}
set s to "-rwx------ 0 286 512 Jun 06 12:36
demo10.log
-rwx------ 0 286 512 Jun 06 12:37 demo11.log
-rwx------ 0 286 512 Jun 06 12:38 demo12.log
-rwx------ 0 286 512 Jun 06 12:39 demo13.log
-rwx------ 0 286 512 Jun 06 12:40 demo14.log"

set s to RemoveCharacterRuns(space, s)

You don't need to do this at all, Paul, if you use negative indices.

Thanks NG,
But the OP asked the question, and got several responses on how to do the extraction, I wanted to round out the field of choices.
The handler I posted removes character runs at a prodigious pace even over large text blocks. Everyone should read through it to see why. It's a clever method that came from a collaboration with one of the better scripter's on the list. You!
set AppleScript's text item delimiters to " "
repeat with thisLine in paragraphs of s
tell thisLine
set the end of fileData to {(text items 5 thru 7) as text, text item
-1}

And don't forget there's such a thing as direct text extraction:

set the end of fileData to {text from text item -4 to text item -2,
text item -1}

or:

set the end of fileData to {text (text item -4) thru (text item -2),
text item -1}

NG

Doh!

No, I mustn't forget that! Direct extraction is 30-50% faster.

Paul
_______________________________________________
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: Remove extra spaces from a string (From: Nigel Garvey <email@hidden>)

  • Prev by Date: Re: path to over eppc?
  • Next by Date: Re: Bug in iTunes?
  • Previous by thread: Re: Remove extra spaces from a string
  • Next by thread: Remove Menu extras
  • Index(es):
    • Date
    • Thread