C# @“” how do i insert a tab?

后端 未结 12 1119
南笙
南笙 2021-01-17 08:02

Recently i found out i can write in a \" by writing two \" ex @\"abc\"\"def\". I find the @ string literal useful. But how do i write in a tab or n

12条回答
  •  星月不相逢
    2021-01-17 08:26

    That quote escape sequence ("") is the only "escape" that works in verbatim string literals. All other escapes only work in regular string literals.

    As a workaround you may use something ugly like this:

    string.Format(@"Foo{0}Bar", "\t");
    

    or include an actual tab character in the string. That should also work with regular string literals, but whitespace, especially tabs, usually doesn't survive different text editors well :-)

    For newlines it's arguably much easier:

    @"Foo
    Bar";
    

提交回复
热议问题