如何正确使用双引号?(how to use double Quotes correctly?)

系统教程 行业动态 更新时间:2024-06-14 17:04:03
如何正确使用双引号?(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

XmlTextWriter

Thanks 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();

更多推荐

本文发布于:2023-04-24 21:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/933c8f68a977a389043d9cb502a55be9.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何正确   双引号   double   Quotes   correctly

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!