VB不接受这些文本字符串字符

时间:2014-04-21 20:15:51

标签: .net vb.net string literals

我试图在富文本框中找到此文本字符串并将其删除,

Dim String1 As String = "<?xml version= "1.0"  encoding =" UTF-16"?>"

但是,我一直收到“语句结束预期错误”。

感谢您的帮助。

2 个答案:

答案 0 :(得分:4)

我提供答案是怎么回事,因为我提供了答案:)

逃避双引号:

"<?xml version= ""1.0"" encoding ="" UTF-16""?>"

答案 1 :(得分:1)

MSDN documentation on VB.NET string literals中所述:

Within a string, a sequence of two double-quote characters is an escape sequence
representing a double quote in the string.

因此,您需要通过在其前面添加另一个双引号char来转义String字面值中的每个双引号,如下所示:

Dim String1 As String = "<?xml version= ""1.0""  encoding ="" UTF-16""?>"