Dave Heavy Industries Dave Heavy Industries – blog


ASP Classic – Escape string for JS

for those that know me... ASP Classic is a pain I have to deal with every day... the simplest things that you've come to accept from every other language is just painful in ASP Classic. Every time I have to do something that I shouldn't have to do, I try to help as many people as possible not have to work it out for themselves. Here is a function to escape a string for use in JS. Enjoy.

Function js_escape(ByRef input_string)

    If NOT IsNull(input_string) AND input_string <> "" Then
        Dim working_string
        working_string = input_string
        working_string = Replace(working_string, vbNewLine, "\n")
        working_string = Replace(working_string, vbTab, "\t")
        working_string = Replace(working_string, "'", "\'")
        ' .. other escape values/strings you may wish to add
        js_escape = working_string
    End If
End Function
Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.