CalcCafe

C#/.NET Escape

Turn raw text into a ready-to-paste C# string literal, with optional verbatim mode.

Example

Regular literal escaping:

Input:
C:\Users\Ada
She said "hi"

Output:
"C:\\Users\\Ada\nShe said \"hi\""

Verbatim mode only doubles quotes:

@"C:\Users\Ada
She said ""hi"""

How it works

Type or paste text on the left to get the escaped C# literal on the right. Choose a regular (escaped) or verbatim (@"") literal, then copy the result.

Good to know

C#/.NET Escape converts arbitrary raw text into a valid C# string literal so you can paste it straight into your source code without breaking compilation. It is built for .NET developers who need to embed file paths, JSON snippets, SQL queries, regex patterns, or multi-line messages directly in code and want the quoting and escaping handled correctly the first time.

Reach for it whenever copy-pasting raw text would introduce a stray double quote, an unescaped backslash (common with Windows paths like C:\Users), or a literal newline that the compiler rejects. The tool offers two output styles and a wrapping toggle, so you can match whatever your codebase already uses:

Read the result by checking which mode you selected against where you'll paste it: the regular form collapses everything onto a single safe line, while verbatim preserves real line breaks across multiple source lines. The status line also reports the input character count so you can confirm nothing was truncated. With "Wrap with quotes" enabled you get a complete literal ready to assign; disable it if you only want the escaped body to splice into an interpolated or concatenated string.

One practical caveat: verbatim mode does not escape backslashes, so it is not interchangeable with raw strings that contain escape-sensitive content like regex — for patterns with many backslashes the verbatim style is usually what you want, but double-check any embedded quotes are doubled. Because everything runs locally in your browser, you can safely paste secrets, connection strings, or proprietary text without it leaving your device.

Frequently asked questions

What is the difference between regular and verbatim output?
A regular literal escapes characters with backslashes (\n, \t, \", \\). A verbatim literal (prefixed with @) takes text as-is, so backslashes stay literal and only double quotes are escaped by doubling them to "".
How are control and non-ASCII characters handled?
Common control characters use their named escapes (\0, \b, \f, \n, \r, \t, \v). Other control characters and DEL are emitted as \uXXXX. Printable Unicode like accents or symbols is left intact, which is valid in C# source.
Is my data uploaded anywhere?
No — this tool runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.

People also ask

How do you escape a backslash in a C# string?
In a regular C# string literal each backslash must be written as a double backslash (\\), so a Windows path like C:\Users becomes "C:\\Users". Alternatively, use a verbatim literal prefixed with @, where a single backslash is taken literally and needs no escaping.
What is a verbatim string literal in C#?
A verbatim string literal is prefixed with the @ symbol, for example @"C:\path". It treats most characters literally, including backslashes and line breaks, and the only character that needs escaping is the double quote, which is written by doubling it as "".
How do you put a double quote inside a C# string?
In a regular literal, escape each double quote with a backslash, as in \". In a verbatim (@"") literal, write a double quote by doubling it, so "" represents a single quote character.
How do you write a multi-line string in C#?
You can use a verbatim literal (@"...") that spans several source lines, which preserves the actual newlines in the text. In a regular literal you instead represent each line break with the \n escape sequence on a single line.
What is the difference between a verbatim string and a raw string literal in C#?
A verbatim string uses the @ prefix and still requires doubling internal quotes. A raw string literal, introduced in C# 11, uses three or more double quotes ("""...""") and needs no escaping of backslashes or quotes at all, which can be cleaner for content like JSON or regex.
How are Unicode characters represented in a C# string literal?
Printable Unicode characters such as accented letters or symbols can appear directly in C# source and remain valid. Non-printable or control characters are typically written using the \uXXXX escape, where XXXX is the four-digit hexadecimal Unicode code point.
Does escaping text for C# change the runtime string value?
No. Escaping only changes how the text is written in source code; when the program runs, the compiler decodes the escapes back to the original characters. The resulting string value at runtime is identical regardless of whether you used a regular or verbatim literal.

Related tools