Re: Removing characters from a string
Re: Removing characters from a string
- Subject: Re: Removing characters from a string
- From: Paul Skinner <email@hidden>
- Date: Tue, 29 Oct 2002 08:13:04 -0500
On Tuesday, October 29, 2002, at 06:56 AM, Kai Edwards wrote:
on 29/10/02 10:02 am, I wrote:
- or you could do most of it with TIDs, looping through the illegal
characters
instead:
snip
- or better still, this shaves a whisker off the length and time:
---------------------------------------------------
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
---------------------------------------------------
Kai
Looping through only the smallest useful set is always the best option,
and your TIDs loop is tight! I like it.
Minimally this could be...
set AppleScript's text item delimiters to ""
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
Not too long for AppleScript! I thought the original post such a basic
question that it needed the most basic example.
--
Can't make "old8tracks" into a record.
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.