vb.net 如何在字符串变量中插入"字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15860478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to insert " character in string variable?
提问by coditori
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
插入所有内容"和>等
采纳答案by Oded
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 Basicon MSDN:
请参阅MSDN 上的Visual Basic 中的字符串基础知识:
Visual Basic interprets two quotation marks in a string literal as one quotation mark in the string.
Visual Basic 将字符串文字中的两个引号解释为字符串中的一个引号。
回答by MarcinJuraszek
In VB.NET you can escape "by passing it twice in a row:
在 VB.NET 中,您可以"通过连续传递两次来转义:
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"">"

