Re: Quotes in strings sent to JavaScript
Re: Quotes in strings sent to JavaScript
- Subject: Re: Quotes in strings sent to JavaScript
- From: "Mark J. Reed" <email@hidden>
- Date: Thu, 29 Nov 2007 11:32:37 -0500
I'm a bit confused. If you do this in AppleScript:
set myString to "This is some \"quoted\" text";
there are no backslashes in the value of myString. They are a
mechanism that lets you type what you want in a way that the
AppleScript parser can understand, but they go away as soon as the
string is read. So there shouldn't be any backslashes in what you're
sending to JS, unless you go out of your way to put them there, e.g.
set myString to "var myString =\"This is some \\\"quoted\\\" text\";"
That will set myString to a valid JavaScript version of the first line.
On Nov 29, 2007 10:54 AM, Rob Lewis <email@hidden> wrote:
> Thanks for the suggestion, Mark, but the "do script" command returns
> "undefined".
> Looking at the AS event log, it appears that the single-quoted string
> sent to JavaScript still contains all the backslash-escaped double
> quotes. If there was some way I could remove all the backslashes, it
> seems like it ought to work. But I can't see any way to do that in
> AS. It's a bummer that AS can't handle single-quoted strings!
>
> I experimented with writing the XML to a text file in AS (with
> suffix .xml), and it looks fine in BBEdit: no backslashes at all.
>
> Grrrr.
>
>
> On Nov 29, 2007, at 5:49 AM, Mark J. Reed wrote:
>
> > On Nov 29, 2007 8:48 AM, Mark J. Reed <email@hidden> wrote:
> >> set the_JavaScript to "this.metadata = '" & my_XML_string & "';"
> >
> > Actually, it would probably work better to do this:
> >
> > set the_JavaScript to "this.metadata = " & quoted form of
> > my_XML_string & ";"
> >
> > since then AS will take care of quoting any internal apostrophes
> > for you.
> >
> >
> > --
> > Mark J. Reed <email@hidden>
>
>
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden