Re: Today's Question - poke a character in a string
Re: Today's Question - poke a character in a string
- Subject: Re: Today's Question - poke a character in a string
- From: email@hidden (Michael Sullivan)
- Date: Thu, 1 Aug 2002 01:50:09 -0400
- Organization: Society for the Incurably Pompous
>
Begin forwarded message:
>
>
On Wednesday, July 31, 2002, at 02:37 AM, Andy Wylie wrote:
>
>
> set (MyLongString's text items)'s item 400 to ">"
>
set foo to "1234567890"
>
set (foo's text items)'s item 5 to "E"
>
foo
>
--> "1234567890"
But oddly enough it works if you do this:
set (MyLongString's text items)'s item 400 to ">"
set MyLongString to result as string
Or in classic functional fashion:
set foo to (set (foo's text items)'s item 400 to ">") as string
Applescript doesn't put any restrictions on lvalues. What's going on
here is that you're creating a temporary list ("foo's text items" is a
command that returns a list) but not binding it to a variable, then
you're setting that temporary unbound list's item 400. That doesn't
change anything about foo, or any other variable you can access, but it
does produce a result that contains the desired text. You can then bind
to foo if you wish either directly or via the result keyword.
But this method has the drawbacks other folks have been discussing. the
FindAndReplace handler that Arthur posted is the canonical way to F&R in
raw applescript. (though it's also reasonable to do it with regexp
osaxen or by scripting something like BBEdit).
Michael
_______________________________________________
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.