C# Escape / Unescape
Turn raw text into the body of a C# string literal, with backslashes, quotes, tabs and line breaks written as \n, \t and friends, or paste an escaped literal and read it back as plain text.
Input
Output
What Is C# String Escaping?
Paste a Windows path or a chunk of JSON between two double quotes in a .cs file and the compiler stops at the first backslash or quote it doesn't expect. A regular C# literal needs those, and control characters like tabs and line breaks, written as escape sequences. For example, a literal newline in a C# string must be written as \n, a backslash as \\, and a null character as \0. These rules are defined in the C# Strings documentation on Microsoft Learn.
This tool has two modes: Escape converts raw text into a safe C# string literal, and Unescape converts an escaped C# string back to readable text. Both directions are computed locally, so the strings you paste here never reach a server. For an overview of all C# escape sequences, see the C# language specification on string literals.
How to Use This Tool
Choose Mode
Escape is for text you are about to put between quotes in code; Unescape is for a literal you copied out of code or a log and want to read as it really is.
Paste Your Text
Put the text you want to process on the left. Sample drops in a realistic snippet, and Upload reads a file from disk instead.
Get the Result
The output follows your typing on the right. Copy grabs it for pasting between the quotes in your source, and Download saves escaped.txt or unescaped.txt. Once the literal is in place, you can tidy the surrounding code with the C# Formatter.
C# Escape Examples
An error template with quotes, a tab, a line break and a null terminator, before and after:
Raw input (with newline, tab, null char, and quotes)
Escaped C# string output
When C# String Escaping Matters
C# string escaping is needed any time you write a string literal that contains special characters: file paths with backslashes, SQL strings, JSON-formatted strings, or strings containing control characters. A common source of bugs is forgetting to double backslashes in Windows paths: @"C:\Users\name" uses a verbatim string literal that avoids this, but regular string literals still require escaping.
C# 11 introduced raw string literals ("""...""") which allow you to include any character without escaping, and C# 6+ interpolated strings reduce concatenation noise. See What's new in C# 11 for details. For JSON-specific escaping, try the JSON Escape tool.
Frequently Asked Questions
Which characters does Escape mode rewrite?
In a regular C# string literal, you must escape: backslash (\\), double quote (\"), single quote (\'), newline (\n), carriage return (\r), tab (\t), null (\0), alert/bell (\a), backspace (\b), form feed (\f), and vertical tab (\v). Other control characters, plus U+0085, U+2028 and U+2029 (which C# treats as line breaks), come out as \uXXXX. Unescape also reads \uXXXX, \UXXXXXXXX and \x. Watch \x: it takes up to four hex digits, so \x41B is the single character U+041B, not an A followed by a B.
What is the difference between a regular C# string and a verbatim string?
A regular C# string literal uses "" delimiters and requires escape sequences. A verbatim string literal uses @"" and treats backslashes as literal characters, so you can write @"C:\Users\name" instead of "C:\\Users\\name". Inside a verbatim string, double a quote to include it: @"say ""hello""".
What are C# raw string literals?
Introduced in C# 11, raw string literals use three or more double-quote delimiters ("""..."""). They allow any character inside without escaping: great for JSON, regex, or multiline strings. See the raw string literals documentation.
What is the \0 escape sequence in C#?
\0 represents the null character (Unicode code point U+0000). It's distinct from a null reference. Some APIs and file formats use null terminators, and \0 is how you embed one in a C# string literal.
Can I paste a connection string or API key here safely?
Yes. Escaping and unescaping are plain string operations inside this tab and nothing is transmitted. The bigger risk is the next step: a key that ends up as a literal in source code tends to end up in Git too.
Related Tools
If the escaped result looks unreadable, it is often a sign the text belongs in a verbatim @"..." or a raw """ literal instead, which need far fewer escapes.