20

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.

0

1 Answer 1

39

Type { twice to escape it:

$"if(inErrorState){{send 1, \"{val}\" }}" 

BTW you can do the same with double quotes.

Sign up to request clarification or add additional context in comments.

1 Comment

BTW you can do the same [(typing it twice to escape it)] with double quotes. - only if you use @$"..." instead of $"...".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.