如何正确使用双引号?(how to use double Quotes correctly?)
This form works in VB .NET
sendMsg = "<CStatus timestamp=""0"" " & _
"type=""login"" " & _
"cid = """ & cID & """ " & _
"key=""" & loginKey & """ />"
但我不能在C#中工作
sendMsg = "<CStatus timestamp=\"0\" type=\"login\" cid=\"" + cID + "\" key=\"" + loginKey + "\" />";它不会产生同样的效果
我想这是一个输出:
<CStatus timestamp="0" type="login" cid="var_cid" key="var_key"/>;有没有在C#中的任何stringXml命令或另一种方式来使用双引号字符串?
谢谢!
解决它
XmlTextWriter感谢大家!
This form works in VB .NET sendMsg = "<CStatus timestamp=""0"" " & _ "type=""login"" " & _ "cid = """ & cID & """ " & _ "key=""" & loginKey & """ />"But i can't get it work in C#
sendMsg = "<CStatus timestamp=\"0\" type=\"login\" cid=\"" + cID + "\" key=\"" + loginKey + "\" />";it does not give the same effect
I want this as an output:
<CStatus timestamp="0" type="login" cid="var_cid" key="var_key"/>;is there any stringXml command in C# or another way to use double quotes in string?
Thank You!
Solved it with
XmlTextWriterThanks to you all!
最满意答案
另一种选择是使用XElement和XAttribute类,它们都可以在VB和C#中使用:
string cID = "blah"; string loginKey = "foo"; var xml = new XElement("CStatus", new XAttribute("timestamp", "0"), new XAttribute("type", "login"), new XAttribute("cid", cID), new XAttribute("key", loginKey) ); string sendMsg = xml.ToString();Another option is to use the XElement and XAttribute classes which will work both in VB and C#:
string cID = "blah"; string loginKey = "foo"; var xml = new XElement("CStatus", new XAttribute("timestamp", "0"), new XAttribute("type", "login"), new XAttribute("cid", cID), new XAttribute("key", loginKey) ); string sendMsg = xml.ToString();更多推荐
发布评论