用双双引号代替双引号

时间:2019-06-23 18:15:26

标签: vb.net double quote

我需要在完整的xml字符串中将"替换为""

我有这个:

Dim mioxml As String = "< xml version = "1.0" encoding="UTF-8"> < orderid > Range < /orderid>< operation >RangeA2< /operation>< /order>"

mioxml = mioxml.Replace(""","""")

但是在第一行上,我有一个错误(指令预期结束)

所以我认为问题出在mioxml的Dim上。

谢谢

2 个答案:

答案 0 :(得分:0)

您可以在Visual Studio中使用XML文字,请看以下示例:

Dim mioxml As XDocument = New XDocument(
                              New XDeclaration("1.0", "utf-8", "yes"), 
                              <order>
                                <orderid>Range</orderid>
                                <operation>RangeA2</operation>
                              </order>)
Console.WriteLine(mioxml.ToString())

这使您可以编写XML元素,而不必担心转义双引号。

答案 1 :(得分:0)

谢谢大卫,这是我根据您的建议所做的事情。

Dim mioxml As XDocument =
<?xml version="1.0" encoding="UTF-8"?>
<orders xmlns:xsi="http//www.w3.org/2001/XMLSchema-instance">
    <order>
      <orderid>Range</orderid>
      <operation>RangeA2</operation>
    </order>
</orders>

Dim mioxml2 = mioxml.ToString
mioxml2 = mioxml2.Replace("""", """""")
MsgBox(mioxml2.ToString)