Re: Removing characters from a string
Re: Removing characters from a string
- Subject: Re: Removing characters from a string
- From: Kai Edwards <email@hidden>
- Date: Sun, 03 Nov 2002 23:11:57 +0000
on Tue, 29 Oct 2002 16:48:58 -0500, Paul Skinner <email@hidden>
wrote:
>
On Tuesday, October 29, 2002, at 02:18 PM, Kai Edwards wrote:
>
>
>> 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.
>
>
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.
While your setup appears to evaluate each list item reference as a value of
the appropriate class (as one might reasonably expect), mine evidently
doesn't. (The issue was touched on recently in the "Scripting in Excel"
thread[1].)
If your script is intended purely for 'local' use, this may not matter -
but, for distribution across different OS/AS versions, you may want to
consider the inclusion of an explicit evaluation (see below).
>
What does the above version do for you?
Same as before:
--> "this/might not.be a legal:name, "
You may recall that I originally used the "repeat with x from y to z" type
of loop - making the required evaluation with (something like) "someList's
item x". However, with the "repeat with x in y" form, my setup still needs
to evaluate each listed item.
So, the following change to the line in the repeat loop _does_ work:
-------------------------------------------
set {n, text item delimiters} to [NO BREAK]
{(n as string)'s text items, d's contents}
--> "thismight notbe a legalname then"
-------------------------------------------
>
No I still didn't deal with resetting the TIDs.
The inclusion of the empty string at the end of the delimiters list (d) not
only completes the required text stripping process - but also resets AS's
text item delimiters to their default value ("") before the script ends.
I see that you also changed the last couple of lines of my earlier
suggestion but, to avoid falling foul of the message size limit, I'll
respond to that separately.
All the best.
Kai
===========================================
[1] Paul Berkowitz (Thu, 24 Oct 2002 08:52:48 -0700):
>
"ASLG, pp. 256-7, but notice the catch described in the NOTES, requiring
>
'contents of' operator, or else evaluating the list item explicitly to a
>
variable.
--
email@hidden
email@hidden
_______________________________________________
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.