C# Escape / Unescape

Escape text for regular or verbatim C# strings, or decode C# escapes.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

C# Escape and Unescape Online

This tool escapes text for C# string literals and unescapes C# strings back to plain text. Choose between a classic escaped string ("...") and a verbatim string (@"...") and paste the result straight into a .cs file, a Razor view, a LINQPad query, or an appsettings test.

Regular string literals

Inside "..." the compiler interprets backslash sequences, so the escaper converts:

  • " → ", ' → ', and ` → \`
  • line breaks and tabs → \r, \n, \t
  • null, bell, backspace, form feed, vertical tab → \0, \a, \b, \f, \v
  • other control characters → \uXXXX

With Non-ASCII → Escape as \uXXXX, characters such as Ü become \u00DC and emoji use the eight-digit form, e.g. \U0001F680. This keeps sources ASCII-only when an editor or CI pipeline mishandles UTF-8.

Verbatim strings

Turn on Verbatim string (@"...") and the only change is doubling every double quote: He said "hi" → @"He said ""hi""". Backslashes and real line breaks stay as they are, which is why verbatim strings are the idiomatic choice for Windows paths like @"C:\Users\Public" and for Regex patterns. The output is wrapped in @"...", and the Unescape mode recognises that wrapper and reverses the doubling.

Raw string literals (C# 11)

C# 11 added raw string literals delimited by three or more quotes: """{"id": 1}""". Their content needs no escaping at all, and a longer delimiter lets the text contain """ itself. If your project targets .NET 7 or later, raw literals are often the simplest way to embed JSON or XML.

Unescaping

Paste an escaped value from a debugger watch window, a log, or generated code into Unescape to see the real text. Related tools: Java Escape / Unescape and JSON Escape / Unescape.

Frequently Asked Questions

In a regular string "..." the backslash starts an escape sequence, so a path needs double backslashes: "C:\\temp". In a verbatim string @"..." backslashes and line breaks are literal and the only escape is "" for a double quote: @"C:\temp". Verbatim strings are popular for file paths, regular expressions, and multi-line SQL.

\' \" \\ \0 \a \b \f \n \r \t \v, \xH to \xHHHH (variable length), \uXXXX, and \UXXXXXXXX for characters outside the Basic Multilingual Plane. The unescaper understands all of these. (C# 13 also added \e for the ESC character; write it as \u001B for older compilers.)

\x takes one to four hex digits, so "\x41BC" is a single character U+41BC, not "A" followed by "BC". To avoid this trap the escaper uses the fixed-length \uXXXX form for control and non-ASCII characters.

C# 11 raw string literals ("""...""") need no escaping at all – quotes, backslashes, and line breaks are literal, and interpolation uses $$"""...{{x}}...""" when braces appear in the text. They are ideal for JSON and XML test data on .NET 7+. For older frameworks use a regular or verbatim string.