Search code examples
vb.netstringvariablesspecial-characters

How to insert " character in string variable?


How to insert this?

Dim SpCharacter As String = " " "

or

Dim XMLSitemap As String = "<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">"

insert with all Content " and > and etc


Solution

  • You need to escape it by doubling it:

    Dim SpCharacter As String = " "" "
    
    Dim XMLSitemap As String = "<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"">"
    

    See String Basics in Visual Basic on MSDN:

    Visual Basic interprets two quotation marks in a string literal as one quotation mark in the string.