首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vb.net字符串生成器双引号

vb.net字符串生成器双引号
EN

Stack Overflow用户
提问于 2016-07-06 01:33:05
回答 1查看 515关注 0票数 0

我已经使用stringbuilder很长一段时间了,以前从来没有出现过这个问题。在本例中,我使用字符串构建器将一个冗长的XML块组合在一起,最后将其放入一个字符串中以提交给一个web服务。在ToString中,所有的双引号都会转换为双引号。

代码语言:javascript
复制
Dim tXML As New StringBuilder
Dim tt As String

tXML.Append("<?xml version=" & """" & "1.0" & """" & " encoding=" & """" & "UTF-8" & """" & "?>")
tt = tXML.ToString


'At this point the value of tXML is what I'd expect: 
    {<?xml version="1.0" encoding="UTF-8"?>}

'However the value of tt is
    "<?xml version=""1.0"" encoding=""UTF-8""?>"

'this method of double-quotes produces the same result
    tXML.Append("<?xml version=""1.0"" encoding=""UTF-8""?>")

这应该很简单,但我感到困惑。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-07-06 22:58:18

使用StringBuilder组装Xml似乎不是最好的方法。为什么不将Xml类与VB.Net的XML文本一起使用呢?

代码语言:javascript
复制
Imports System.Xml.Linq

Private Sub createXml()

    Dim xDoc As New XDocument()

    xDoc.Declaration = New XDeclaration("1.0", "utf-8", "yes")

    xDoc.Add(<Root attr="x">
                <SomeElement>Some Value</SomeElement>
            </Root>)

    xDoc.Save("c:\somefolder\myfile.xml")

End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38209359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档