Search code examples
vb.netstringstring-constant

Declare HTML tag as a string in VB.NET


I'm trying to assign the following HTML as a value to variable type string

    'here's the tag 
   '$("#close").click(function(){$.notifyBar({ html: "Click 'close' to hide notify bar", close: true, delay: 1000000 });});

        Dim htmltag = "$("#close").click(function(){$.notifyBar({ html: "Click 'close' to hide notify bar", close: true, delay: 1000000 });});"

I got a lot error message about the quotation in the string.


Solution

  • You need to use escape characters on the quotations otherwise they break the variable input. The VB.net escape for quotations is double quote:

    Dim htmltag = "$(""#close"").click(function(){$.notifyBar({ html: ""Click 'close' to hide notify bar"", close: true, delay: 1000000 });});"
    

    In your example, the compiler would see the string as:

    Dim htmltag = "$("
    

    With lots of unknown stuff after it!

    Other languages have different escape characters, javascript for example is backslash.