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

Re: Removing characters from a string


  • Subject: Re: Removing characters from a string
  • From: Paul Skinner <email@hidden>
  • Date: Tue, 29 Oct 2002 16:48:58 -0500

On Tuesday, October 29, 2002, at 02:18 PM, Kai Edwards wrote:

on Tuesday, October 29, 2002, at 06:56 AM, Paul Skinner
<email@hidden> wrote:

On Tuesday, October 29, 2002, at 06:56 AM, Kai Edwards wrote:

---------------------------------------------------
set tid to text item delimiters
set l to {".", ",", "/", ":", tid}
set n to "this/might not.be a legal:name, then again, it could be."
set text item delimiters to l's item 1
repeat with i from 2 to count l
set {n, text item delimiters} to {(n as string)'s text items, l's item
i}
end repeat
set n to n as string
if n's length > 32 then set n to n's text 1 thru 32
n
---------------------------------------------------

Looping through only the smallest useful set is always the best option,
and your TIDs loop is tight! I like it.

Thanks, Paul.

TIDs avoided the need for character-by-character analysis, while the
manipulation of text, rather than list items, also helped to boost the
overall speed. (OMM, the above variation generally runs 9-10 times faster
than the original suggestion.)

Minimally this could be...

snip fouled code

Unfortunately, that's just a little too minimal for my machines:

--> "this/might not.be a legal:name, "

I'm afraid that the TIDs also remain set to the last item in the list (":")
- which of course may produce unexpected results elsewhere.

I am such a naughty boy. I always write handler's that restore the TIDs, but if anyone uses TIDs without first assuring themselves that they are correctly set then woe be unto them!

(Tested on OS 8.1/AS 1.1.2, OS 9.1/AS 1.5.5)

Best wishes.

Kai


Oops!
I left out the last delimiter; null-"". I was sleepy.


set n to "this/might not.be a legal:name, then again, it could be."
repeat with d in {",", ".", "/", ":", ""}
set {n, text item delimiters} to {(n as string)'s text items, d}
end repeat
if length of (n as string) is greater than 32 then set n to (n as string)'s text 1 thru 32
-->"thismight notbe a legalname then"


OS 10.2.1 / AS 1.9.
Interesting that it failed to perform ANY work on your box. It left only the final colon here, due to the missing null delimiter.
What does the above version do for you?
No I still didn't deal with resetting the TIDs. I put these kind of useful code chunks into pre-formed handler templates that deal with all of that stuff.
--
Paul Skinner
_______________________________________________
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: Removing characters from a string (From: Kai Edwards <email@hidden>)

  • Prev by Date: [Apple List Admin] Re: using non-ascii chars on this mailing list
  • Next by Date: [Apple List Admin] Re: using non-ascii chars on this mailing list
  • Previous by thread: Re: Removing characters from a string
  • Next by thread: Illustrator guides - was illustrator-10-scripting: removing things
  • Index(es):
    • Date
    • Thread