2010-08-31 180 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