2017-10-05 154 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

没有先生,这绝对不是我的代码 –

相关问题