C# String Escape and Unescape
ED-27Paste text to escape it for a regular or a verbatim @"" C# string, or paste a literal to read it back as plain text. Both directions work for both styles.
Runs in your browser. Nothing is uploaded.
Text or C# string
Result
How to use it
- Paste the text, or the contents of a C# string, into the input box.
- Choose Escape (regular), Escape (verbatim), or the matching Unescape button.
- Tick options such as Escape non-ASCII or Add surrounding quotes if you need them.
- Copy the result, or download it as a .txt file.
Regular strings
A regular literal escapes the backslash and double quote as \\ and \", and writes \0 \a \b \t \n \v \f and \r for the control characters that have short forms. Other control characters become \u00XX. Characters outside ASCII are left as they are unless you tick Escape non-ASCII, which writes each UTF-16 unit as \uXXXX. Single quotes can be escaped by option.
Verbatim strings
A verbatim literal, written @"...", has only one escape: a double quote is written as two double quotes. Backslashes and line breaks stay exactly as typed, which is why it suits file paths and multi-line text. Escape (verbatim) doubles the quotes and can add the @" and closing quote for you. Unescape (verbatim) reverses it and reports a single double quote that is not doubled.
Reading escapes back
Unescape (regular) understands \' \" \\ \0 \a \b \f \n \r \t \v, \uXXXX, \UXXXXXXXX and \x with one to four hex digits. The \x form takes as many digits as it finds, so \x41B is one character, not A followed by B. One pair of surrounding double quotes is removed if present. Interpolated strings with $ and raw string literals are not covered.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Unknown escape | A backslash is followed by a character that C# does not define as an escape. | Double the backslash for a literal one, or use a valid escape. |
is above U+10FFFF | A \U escape names a number larger than the last Unicode code point. | Use a value up to 10FFFF. |
would end the string | A double quote inside a quoted regular string is not escaped. | Write it as \". |
single double quote | A verbatim string has a double quote that is not written as two. | Double the quote, as in "". |
Questions people ask
How do I escape a string in C#?
Replace the backslash with \\, the double quote with \" and line breaks with \n. Or use a verbatim string, where only the double quote changes, to "". Paste your text here and click the Escape button for the style you want.
What is the difference between regular and verbatim strings?
A regular string uses backslash escapes, so a path needs doubled backslashes. A verbatim string starts with @" and treats backslashes and line breaks literally, with only "" meaning one double quote. This tool converts both forms in both directions.
How do I write a double quote inside a C# string?
In a regular string write \", and in a verbatim string write "" (two double quotes). The tool applies the right one for the button you press, and Unescape turns it back to a single quote.
Does it support interpolated or raw string literals?
No. Interpolated strings with a $ prefix have braces that need their own handling, and raw string literals with triple quotes follow different rules. Only regular and verbatim literals are covered.
How are emoji written when I tick Escape non-ASCII?
As two \uXXXX escapes, since C# strings are UTF-16 and an emoji is a surrogate pair. The grinning face emoji becomes \uD83D\uDE00. Unescape joins such a pair back into one character.
Is my text uploaded?
No. The tool runs in your browser, so the code or text you paste is not sent anywhere. It makes no network calls, needs no account, and nothing is stored once you close the page.
About this tool
Regular escape writes \\, \", \0, \a, \b, \t, \n, \v, \f and \r, and turns other control characters into \u00XX. Verbatim escape only doubles each double quote; line breaks and backslashes stay as typed, which is how a @"..." literal works. Unescape of a regular string also reads \', \UXXXXXXXX and \x with 1 to 4 hex digits (which takes as many digits as it can, so \x41B reads as one character). If the text begins and ends with a double quote, one pair is removed. Interpolated ($"") strings, raw string literals (""") and format placeholders are not covered.