• 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: Today's Question - poke a character in a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Today's Question - poke a character in a string
      • From: Andy Wylie <email@hidden>
  • Prev by Date: Re: Display dialog + compiled scripts
  • Next by Date: Re: get default browser?
  • Previous by thread: Re: Today's Question - poke a character in a string
  • Next by thread: Re: Today's Question - poke a character in a string
  • Index(es):
    • Date
    • Thread