2010-08-31 243 views
-2

我想在c#字符串中添加双引号。C#字符串中的双引号

string searchString = "123"; 
string inputString = "No matches found for "+ "\""+searchString + "\""; 

输出:No matches found for "123"

+2

,什么是你的问题? – LukeH 2010-08-31 12:03:09

+10

这里有问题吗? – codaddict 2010-08-31 12:03:19

+1

那你有什么问题? – KeatsPeeks 2010-08-31 12:03:26

回答

1

你有什么要出示你的期望是什么:

No matches found for "123"

您也可以尝试:

string searchString = "123"; 
string inputString = String.Format(@"No matches found for ""{0}""!", searchString); 
4

我认为你需要string.format

例如:

string.format("No matches found for \"{0}\"", searchString); 
-4
string inputString = String.Format(@"No matches found for \"{0}\"", searchString); 
+5

这甚至不会编译!正确的转义字符串中的双引号是“”(双引号的两倍),所以它会变成String.Format(@“No matches found for”“{0}”“”,searchString); – maciejkow 2010-08-31 12:11:11

+0

对上面的评论:为什么不只是说应该删除符号? – jgauffin 2010-08-31 12:24:41

+0

@jgauffin,:)投票就是力量! :) – 2010-08-31 12:42:21