Input

Mode:

Output

What Is C# String Escaping?

In C#, string literals require certain characters to be escaped so the compiler can parse them correctly. Backslashes, double quotes, single quotes, newlines, tabs, carriage returns, null characters, alert (bell), backspace, form feed, and vertical tabs must all be 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. Everything runs locally in your browser — nothing is sent to a server. For an overview of all C# escape sequences, see the C# language specification on string literals.

How to Use This Tool

1

Choose Mode

Select Escape to convert raw text to a safe C# string, or Unescape to convert an escaped C# string back to plain text.

2

Paste Your Text

Paste your input into the left editor. You can also click Sample to load a realistic example, or Upload to load a file.

3

Get the Result

The right panel updates automatically as you type. Use Copy or Download to get the result. To format C# code, try C# Formatter.

C# Escape Examples

Here is a real-world example. The raw text contains a newline, a tab, a null char, and double quotes:

Raw input (with newline, tab, null char, and quotes)

Input

Escaped C# string output

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

What characters need to be escaped in a C# string?

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). Unicode escapes (\uXXXX) are also supported.

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.

Does this tool send my data to a server?

No. All escaping and unescaping happens entirely in your browser using JavaScript. Your input is never transmitted anywhere — it's safe to use with passwords, API keys, or any private data.

Related Tools

References: C# Strings — Microsoft Learn · C# Language Specification — String Literals · What's new in C# 11