How to express a string literal containing double quotes without escape characters?

Is there any C # syntax with which I can express strings containing double quotes without escaping them? I often copy and paste the lines between the C # source code into other applications, and it is inconvenient to keep adding and removing backslashes.

Eg. currently for the next line (simple example)

“No,” he said.

I write in C # "\"No,\" he said."

But I would rather write something like Python '"No," he said.' or Ruby %q{"No," he said.} , so I can copy and paste the contents verbatim into other applications.

+4
source share
2 answers

I often copy and paste the lines between the C # source code into other applications, and it is inconvenient to keep adding and removing backslashes.

Then it sounds like you probably shouldn't have lines in your source code.

Instead, create text files embedded in your assembly and load them dynamically ... or create resource files so that you can search for lines by key.

There is no string literal form in C # that will allow you to express a double quote as only one double quote character in the source code.

+9
source

You can try this, but you are still effectively avoiding:

 string s = @"""No,"" he said."; 
+3
source

All Articles