如何在字符串变量中插入“字符?

时间:2013-04-07 08:37:41

标签: vb.net string variables special-characters

如何插入?

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">"

插入所有内容&gt;

2 个答案:

答案 0 :(得分:1)

你需要通过加倍来逃避它:

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"">"

请参阅MSDN上的String Basics in Visual Basic

  

Visual Basic将字符串文字中的两个引号解释为字符串中的一个引号。

答案 1 :(得分:0)

在VB.NET中,您可以通过连续两次传递来转义"

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"">"