2017-10-05 152 views
-2

快速問題,我無法找到答案在線或只是不知道如何尋找它。 我有一個問題與此代碼C#將字符串放在另一個字符串之前

string stackoverflowcommunityisawesome = "string " + RandomString(5) + " = '" + RandomString(5) + "'; " ; 

目前的輸出爲:

串AGKHAOH = 'kaosgkoko';

當我希望它是:

串AGKHAOH = 「kaosgkoko」;

我試圖把@"""代替'"但輸出是這樣的:

串AGKHAOH = + RandomString(5)+;

試用"\""以及 - 整個代碼變成紅色。任何提示都表示讚賞。

+1

代碼段是不完整的權利? 你一定是做錯了,「是雙引號逃脫 – rmjoia

+1

嘗試更改爲」 – Quintium

+1

「= \」「+ RandomString(5)+」\「;」 – owairc

回答

1

只是逃避,像這樣的報價:。"\""

string funone = "public static void "+RandomString(5)+ "(string " + RandomString(5) + ") { " + Environment.NewLine +      
       "string " + RandomString(5) + " = \"" + RandomString(5) + "\';" 
       + Environment.NewLine + 
       "}"; 
+0

哇感謝它的工作 –

2

\」是要走的路,如果你與那麼有錯誤得到一個錯誤的其他地方

+0

每個人都使用相同的答案評論.. – rmjoia

+0

道歉不夠快,看不到他們 – akerra

+1

好意見是要求澄清,而不是提供一個答案。 – orhtej2

0

要麼使用逐字字符串文字或轉義「使用反斜槓。這應該工作。

string funone = "public static void "+RandomString(5)+ "(string " + RandomString(5) + ") { " + Environment.NewLine + "" + "string " + RandomString(5) + " = \"" + RandomString(5) + "\"; " + Environment.NewLine + "";

+0

感謝您的答覆哥們已經得到了答案,但感謝加入:) –

0

如果這真的是你的代碼,我想改變一下:

 StringBuilder funone = new StringBuilder(); 
     funone.AppendLine($"public static void {RandomString(5)} (string {RandomString(5)}) {{"); 
     funone.AppendLine($"string {RandomString(5)} = \"{RandomString(5)}\";"); 
     funone.AppendLine($"byte[] {RandomString(5)} = new byte[{rnd.Next(888, 133333)}];"); 
     funone.AppendLine($"string {RandomString(5)} = \"{RandomString(5)}\";"); 
     funone.AppendLine($"string {RandomString(5)} = \"{RandomString(5)}\";"); 
     funone.AppendLine($"byte[] {RandomString(5)} = new byte[{rnd.Next(888, 133333)}];"); 
     funone.AppendLine($"string {RandomString(5)} = \"{RandomString(5)}\";"); 
     funone.AppendLine($"string {RandomString(5)} = \"{RandomString(5)}\";"); 
     funone.AppendLine($"byte[] {RandomString(5)} = new byte[{rnd.Next(888, 133333)}];"); 
     funone.AppendLine($"while (true) {{ "); 
     funone.AppendLine($"string {RandomString(5)} = \"{RandomString(5)}\";"); 
     funone.AppendLine($"byte[] {RandomString(5)} = new byte[{rnd.Next(888, 133333)}];"); 
     funone.AppendLine($"string {RandomString(5)} = \"{RandomString(5)}\";"); 
     funone.AppendLine($"string {RandomString(5)} = \"{RandomString(5)}\";"); 
     funone.AppendLine($"byte[] {RandomString(5)} = new byte[{rnd.Next(888, 133333)}];"); 
     funone.AppendLine($"string {RandomString(5)} = \"{RandomString(5)}\";"); 
     funone.AppendLine($"string {RandomString(5)} = \"{RandomString(5)}\";"); 
     funone.AppendLine("}"); 
     funone.AppendLine(); 
     string output = funone.ToString(); 
     string path = @"C:\core\junk.txt"; 
     for (int i = 0; i < 5; i++) 
     { 
      File.AppendAllText(path, output); 
     } 
+0

沒有先生,這絕對不是我的代碼 –

相關問題