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

Re: Wierd error


  • Subject: Re: Wierd error
  • From: Nigel Garvey <email@hidden>
  • Date: Wed, 24 Sep 2003 02:50:17 +0100

Paul Berkowitz wrote on Tue, 23 Sep 2003 08:05:15 -0700:

>You like typing quote marks? This will run much faster, since searching text
>("is in") is much, much faster than searching lists:
>
>my trim(" *%*&*!@#$^ |BLOW, JOE|* ^&*))&%^^%$ ")
>--> BLOW, JOE
>
>on trim(inputtext)
> set valids to
>"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
> repeat with i from 1 to (count inputtext) -- count is faster too, and no
>list
> if character i of inputtext is in valids then
> set startValid to i
> exit repeat
> end if
> end repeat
> repeat with j from 1 to (count inputtext)
> if character (-j) of inputtext is in valids then
> set endValid to j
> exit repeat
> end if
> end repeat
> set trimmedText to text startValid thru (-endValid) of inputtext
>end trim

And don't forget 'considering case', arranging the most likely characters
towards the beginning of the 'valids' string, and only counting
'inputtext' once. As a safety feature, the whole process could go in a
'try' block with the first repeat going up to (count inputtext) + 1. If i
gets that far, it means there are no valid characters in inputtext and
the attempt to test beyond the end of the string will cause an error.
'trimmedText' can then be set to "" in the 'on error' block.

NG
_______________________________________________
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.

  • Prev by Date: Re: Weird error
  • Next by Date: Converting enums to strings and v.v.
  • Previous by thread: Re: Wierd error
  • Next by thread: Re: Wierd error
  • Index(es):
    • Date
    • Thread