Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there C# raw string with delimiter like in C++?

In C++, we have raw literal string using R"()" with delimiter. So this code below is fine:

const char SOMETEXT[] = R"+-+-+(<link rel="icon" href="img/favicon.png">)+-+-+"

I don't know how to do it in C#, as far as I know there is a verbatim string using @"" but it doesn't have delimiter. And this causes error:

string SOMETEXT = @"<link rel="icon" href="img/favicon.png">";

Is there any raw literal string with delimiter in C#? Because I don't want to change the string, it will PITA to edit later.

like image 349
ErinQvnm Avatar asked Nov 26 '25 02:11

ErinQvnm


1 Answers

No, there's nothing like this in C#. If this is arbitrary text that you'll need to edit reasonably frequently, you might want to put it into a resource file instead.

Another alternative I often use for JSON that appears in tests etc is to just use single quotes instead of double quotes, then replace afterwards:

string text = "<link rel='icon' href='img/favicon.png'>".Replace('\'', '"');
like image 167
Jon Skeet Avatar answered Nov 27 '25 15:11

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!