• 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: Luther Fuller <email@hidden>
  • Date: Mon, 25 Jul 2011 14:50:22 -0500

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.
(And, yes, there are a couple of lines in there that you don't need.)

 _______________________________________________
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

References: 
 >Trim space chars from start of line (From: "Zavatone, Alex" <email@hidden>)

  • Prev by Date: Re: I know this is not the right place to ask this buuut.
  • Next by Date: Re: I know this is not the right place to ask this buuut.
  • 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