C# two double quotes

前端 未结 11 1491
灰色年华
灰色年华 2020-12-10 03:54

I want to print two double quotes in C# as the output. How to do this?

I mean the output should be: \"\" Hello World \"\"

相关标签:
11条回答
  • 2020-12-10 04:48

    Use a backslash before the double quotes: \"

    0 讨论(0)
  • 2020-12-10 04:49

    Escape them:

    Console.WriteLine("\"Hello world\"");
    
    0 讨论(0)
  • 2020-12-10 04:54

    Using a @-char before the 'normal' double quotes will result in printing every special char between those dubble quotes

    string foo = @"foo "bar"";
    
    0 讨论(0)
  • 2020-12-10 04:54

    StringBuilder sb = new StringBuilder(); sb.Append("\"Hello World \""); string s = sb.ToString();

    0 讨论(0)
  • 2020-12-10 04:55

    you can output with the @, which will automatically escape special characters.

    string output = "\"\" Hello World \"\"";
    
    string output = @""""" Hello World """"";
    
    0 讨论(0)
提交回复
热议问题