OutFall
OutFall

Reputation: 482

Old VB Script how to escape double quotes inside double quotes

I am trying to do something like this:

<script>
   var comment = "<%=Server.HTMLEncode(rc("comment"))%>";
</script>

What I tried and it didn't work:

var comment = "<%=Server.HTMLEncode(rc('comment'))%>";
var comment = "<%=Server.HTMLEncode(rc("""comment"""))%>";
var comment = "<%=Server.HTMLEncode(rc(" & chr(34) & "comment" & chr(34) & "))%>";

Also var comment = '<%=Server.HTMLEncode(rc("comment"))%>'; doesn't work because the string that is returned might have ' in it and so the sentence breaks in the middle.

Upvotes: 1

Views: 413

Answers (1)

ZippyV
ZippyV

Reputation: 13068

Try something like:

var comment = "<%= Replace(Server.HTMLEncode(rc("comment")), """", "\""") %>";

This function replaces " with \"

Upvotes: 2

Related Questions