Is there a C# syntax with which I can express strings containing double quotes without having to escape them? I frequently copy and paste strings between C# source code to other apps, and it's frustrating to keep adding and removing backslashes.
Eg. presently for the following string (simple example)
"No," he said.
I write in C# "\"No,\" he said."
But I'd rather write something like Python '"No," he said.'
, or Ruby %q{"No," he said.}
, so I can copy and paste the contents verbatim to other apps.
To represent a double quotation mark in a string literal, use the escape sequence \". The single quotation mark (') can be represented without an escape sequence. The backslash (\) must be followed with a second backslash (\\) when it appears within a string.
Character literals are enclosed in single quotation marks.
It (more or less) means "treat the next character as special" - so here java thinks you are trying to put a double quote inside a quoted string. sometimes you need to do that. To get around this, you have to tell java to treat the backslash in a special way. so, you need TWO backslashes.
I frequently copy and paste strings between C# source code to other apps, and it's frustrating to keep adding and removing backslashes.
Then it sounds like you probably shouldn't have the strings within source code.
Instead, create text files which are embedded in your assembly, and load them dynamically... or create resource files so you can look up strings by key.
There's no form of string literal in C# which would allow you to express a double-quote as just a single double-quote character in source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With