C# / .NET Escape / Unescape
This C# escaper converts text into the body of a regular string literal — quotes, backslashes, line breaks, tabs and control characters all get their escape sequences. It is worth knowing that C# has two kinds of literal with different rules: a regular literal uses backslash escapes, which is what this produces, while a verbatim literal prefixed with @ treats backslashes as ordinary characters and escapes a double quote by doubling it instead. Pasting this output into a verbatim literal would leave the backslashes visible. Everything runs in your browser.
How it works
Escapes a value for a regular C# string literal — quotes, backslashes, line breaks, tabs and control characters all get their escape sequences.
This is for regular literals. A verbatim string (one prefixed with @) uses different rules entirely: backslashes are literal and a double quote is written by doubling it.
Escaping runs entirely in your browser — nothing you paste is sent to a server.
0 characters in · 0 characters out
How to escape a C# string
- Paste your text into the input on the left.
- Choose the quote style your literal uses.
- Copy the escaped body into your C# source.
Regular literals, not verbatim ones
C# has two kinds of string literal and they escape differently. A regular literal — the ordinary
kind — uses backslash escapes, which is what this tool produces. A verbatim literal, written with
an @ prefix, treats backslashes as literal characters and escapes a double quote by doubling it
instead. Do not paste this output into a verbatim literal: the backslashes would survive as themselves.
What gets escaped
- Your quote character and backslashes.
- Line breaks, carriage returns and tabs as
\n,\rand\t. - Other control characters as
\uXXXX.
Common use cases
- Embedding JSON, XML or a file path in a C# string constant.
- Building a multi-line literal for a test fixture.
- Decoding an escaped value found in a config file or log.
Frequently asked questions
What is the difference between a regular and a verbatim C# string?
A regular literal uses backslash escapes, so a Windows path needs doubled backslashes. A verbatim literal, written with an @ prefix, treats backslashes literally and escapes a double quote by doubling it. This tool produces output for regular literals.
Can I paste this into a verbatim string?
No. The backslashes would survive as themselves, so a \n would appear as the two characters backslash and n rather than a line break. Convert the literal to a regular one first, or double the quotes by hand.
Which characters get escaped?
Your quote character, backslashes, line breaks, carriage returns and tabs, plus any remaining control characters as \uXXXX.
Does it work for VB.NET or F# too?
F# regular strings follow the same backslash escaping, so the output applies. VB.NET has no backslash escapes at all — it doubles quotes instead — so use the CSV-style doubling rather than this.
Is my text sent anywhere?
No. Escaping is done entirely in your browser.
Related tools
JavaScript Escape / Unescape
This JavaScript escaper prepares any text to sit inside a string literal without breaking it.
Java Escape / Unescape
This Java escaper handles the sequences Java accepts, including ASCII-only output for properties files.
JSON Stringify & Escape
This JSON stringify tool escapes a document into a string literal you can embed, and unescapes it again.