Escape double quotes in a string

后端 未结 6 2101
轮回少年
轮回少年 2020-11-22 10:35

Double quotes can be escaped like this:

string test = @\"He said to me, \"\"Hello World\"\". How are you?\";

But this involves adding chara

6条回答
  •  太阳男子
    2020-11-22 11:13

    One solution, is to add support to the csharp language so that "" isn't the only scheme used for strings.

    For another string terminator to the C# language - I'm a fan of backtick in ES6.

    string test = `He said to me, "Hello World". How are you?`;
    

    But also, the doubling idea in Markdown might be better:

    string test = ""He said to me, "Hello World". How are you?"";
    

    The code does not work at the date of this post. This post is a solution where the visitors to this Q&A jump onto this csharplank ticket for C# and upvote it - https://github.com/dotnet/csharplang/discussions/3917

提交回复
热议问题