据我所知,带有 @ 的字符串需要一组双引号才能将引号插入到字符串中?
我已经尝试过该原则但无济于事。以下行有效,但如果我用参数值替换这些字符串,那么我似乎无法获得正确的编译值
var node = doc.SelectSingleNode(@"//node[@label = ""Chemist Name""]/node[@label = ""John,Smith""]");
我的尝试(其中我尝试了几个版本并最终在这里,我现在放弃了!)
var node = doc.SelectSingleNode(@"//node[@label = " + ""+parentID+"" + "]/node[@label = " + ""+ name +"" + "]");
谁能帮帮我?
最佳答案
使用单引号:
var node = doc.SelectSingleNode
(@"//node[@label = 'Chemist Name']/node[@label = 'John,Smith']");
var node = doc.SelectSingleNode(
string.format(@"//node[@label = '{0}']/node[@label = '{1}']"
, parentID, name));
关于c# - 在@字符串中添加双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5621082/