This is probably a really simple question but I can't seem to get my head around it. I need to have a string that contains \"
without it seeing it as an escape character. I tried using @
but it won't work. The only other way I thought of doing this would be to use \u0022
but don't want to unless I can help it.
Desired string - string s = "\"\""; // Obviously this doesn't work!
Desired console output - \"\"
Hope this makes sense.
Thanks!
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.
If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.
split("(? =\"[^\"]. *\")");
You can put a backslash character followed by a quote ( \" or \' ). This is called an escape sequence and Python will remove the backslash, and put just the quote in the string. Here is an example. The backslashes protect the quotes, but are not printed.
You can use the literal, but you need to double-up quotes.
string s = @"\""\""";
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