问题描述
我一定是在遗漏一些东西 - 我是一位经验丰富的C ++程序员,现在正在使用
C#整体我喜欢这种语言,但发现了许多奇怪的变化......无论如何我是
写作aspx背后的代码。在这个C#方法中,我正在构建一个XML
字符串,用于插入数据库。该字符串应该导致:
< row FIELD1 =" value1" FIELD2 = QUOT;值2" \>
我正在使用字符串类型变量而我无法获得双引号
正确添加我已经尝试了所有的东西我应该这样工作
如下:
string sXML;
sXML ="< row" ;;
//我试过这个
sXML + =" FIELD1 = \" value1 \" " ;;
sXML + =" FIELD2 = \" value2 \" \\>" ;;
//这个
sXML + = @" FIELD1 ="" value1"" " ;;
sXML + = @" FIELD2 ="" value2"" \\>" ;;
//这个
sXML + =" FIELD1 = \ u0022value2 \ u0022";
sXML + =" FIELD2 = \ u0022value2 \ u0022 \\>" ;;
在所有情况下,当我检查这些案例时sXML字符串和/或插入数据库的值
导致:
< row FIELD1 = \" value1 \" FIELD2 = \" value2\" \\>
为什么结果字符串中会显示\?像C ++这样的东西是如此简单直接用C语言让我疯狂#我错过了什么
?
Brett ++
这样的
缺少
I must be missing something - Im a veteran C++ programmer now working with
C# overall I like the language but find many weird changes... Anyway Im
writing code behind an aspx. In this one C# method I am building an XML
string to be insterted into a database. This string should result in:
<row FIELD1="value1" FIELD2="value2" \>
I am using a string type variable and I cannot get the double quotes to be
added properly I have tried all of the things that are supposed to work such
as:
string sXML;
sXML = "<row ";
// Ive tried this
sXML += "FIELD1=\"value1\" ";
sXML += "FIELD2=\"value2\" \\>";
// and this
sXML += @"FIELD1=""value1"" ";
sXML += @"FIELD2=""value2"" \\>";
// and this
sXML += "FIELD1=\u0022value2\u0022 ";
sXML += "FIELD2=\u0022value2\u0022 \\>";
In all cases when I examine these cases the sXML string and/or the value
inserted into the database results in:
<row FIELD1=\"value1\" FIELD2=\"value2\" \\>
Why are the \ showing up in the result string? Its things like this that
were so straight forward in C++ that drive me nuts in C# what am I missing
?
Brett++
such
missing
这篇关于C#中的双引号 - 简单的东西,但我觉得我很疯狂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!