jsonecho

.NET (C#) Escape

Paste your text and get it escaped for .NET (C#), ready to paste into code or data.

Loading the tool...

How to use .NET (C#) Escape

  1. Paste or type the text you want to escape.
  2. Adjust the options if you need to.
  3. Copy the escaped result.

About .NET (C#) Escape

C# has two kinds of string literals. A regular one, "...", needs backslash escapes for quotes, backslashes and line breaks. A verbatim one, @"...", takes everything literally except the double quote, which you double. This tool can produce either.

It helps when you embed JSON, XML, a file path or a regular expression in C# code. In Windows paths in particular the backslashes double quickly. A verbatim string is the neater choice there.

What gets escaped

Backslash becomes \\, quotes become \" and \', line break \n, carriage return \r, tab \t, null \0, form feed \f, vertical tab \v. In verbatim mode only " becomes "".

Frequently asked questions

What is the difference between regular and verbatim strings?

In a regular string the backslash starts an escape sequence. In a verbatim string, written @"...", it does not, which makes file paths and regexes far more readable. Only the double quote has to be doubled.

Can a verbatim string contain line breaks?

Yes, it can span several lines, and the line breaks become part of the string.

What about interpolated strings?

In $"..." strings, curly braces also have a special meaning and must be doubled. This tool does not double them.

Since C# 11 there are raw string literals, should I use them?

If your project can use them, triple-quoted raw strings need no escaping at all, which is handy for JSON.

More in Escape and Text

All tools →