I am hoping to use a "{" inside a string interpolation statement but I'm having trouble finding the escape character to do it.
var val = "ERROR_STATE";
var str = $"if(inErrorState){ send 1,\"{val}\" }"
Desired output:
if(inErrorState){send 1,"ERROR_STATE"}
The simple solution is to just not use string interpolation, but I think this way of doing it is easier to read.
Escape sequences You can represent any member of the execution character set by an escape sequence. They are primarily used to put nonprintable characters in character and string literals. For example, you can use escape sequences to put such characters as tab, carriage return, and backspace into an output stream.
\n means new line. It means that the cursor must go to the next line. \r means carriage return.
When writing to an interactive terminal on stdout or stderr , '\r' can be used to move the cursor back to the beginning of the line, to overwrite it with new contents.
\t (Horizontal tab) – We use it to shift the cursor to a couple of spaces to the right in the same line.
Type {
twice to escape it:
$"if(inErrorState){{send 1, \"{val}\" }}"
BTW you can do the same with double quotes.
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