.NET Escape Online — Escape Strings for C#/VB

Escape strings for C# and VB.NET regular string literals — backslash, double quote, \n, \t, and control characters. Browser-only — paste raw text, copy a literal-safe string.

What is .NET String Escaping?

.NET string escaping converts a raw string into a form that can sit between double quotes inside a C# (or VB.NET) source file without breaking compilation. Backslashes are doubled, double quotes prefixed with backslash, and control characters (\n, \r, \t, \b, \f) emitted as their two-character escape sequences.

.NET supports two literal forms: regular strings ("...") that interpret backslash sequences, and verbatim strings (@"...") that take backslashes literally and only escape doubled quotes. This tool produces regular-string output — useful when you want to paste data into existing C# code or generate string constants. The transformation runs entirely in your browser.

How to escape .NET strings — 4 steps

  1. Paste raw text. Drop your unescaped string into the Input panel — Windows paths, multi-line text, regex patterns all welcome.
  2. Click Escape. Backslashes are doubled first to avoid double-encoding, then quotes and control characters are emitted as their backslash sequences.
  3. Verify. Every \ shows as \\, every " as \", and every newline collapses to \n on a single line.
  4. Paste into C# code. Wrap the output in double quotes and drop into your string declaration, const, or test fixture.

Sample input and output

Raw input

C:\Users\admin\config.json
He said "ready" then pressed Enter
	Tab-indented log line

C# regular-string output

C:\\Users\\admin\\config.json\nHe said \"ready\" then pressed Enter\n\tTab-indented log line

C# Compatible

Output uses the exact backslash sequences a C# regular string literal accepts — \\, \", \n, \r, \t, \b, \f.

Backslash-First

Backslashes are escaped first so subsequent passes do not re-encode the new backslashes — produces correct output for paths and regex.

Browser-Only

No source code, connection strings, or secrets leave the browser. The escape runs in JavaScript on your device.

Common use cases

  • check_circleEmbedding Windows file paths in C# code as regular string literals
  • check_circlePreparing regex patterns for Regex.Match without verbatim strings
  • check_circleConverting JSON or YAML payloads into C# const string fixtures for tests
  • check_circleEncoding multi-line SQL queries as single-line C# strings with \n
  • check_circleStoring escaped XML or HTML templates as compile-time string constants
  • check_circleGenerating string literals for code-generation tools and T4 templates
  • check_circlePreparing values for Roslyn syntax-rewriter tests and compiler unit tests
  • check_circleEmbedding regex test fixtures in xUnit and NUnit test assertions

.NET escape vs Java escape vs JSON escape

All three produce backslash-escaped strings, but the supported escape sets differ. .NET adds \a (bell) and \v (vertical tab) on top of the common set and accepts \xN[N..] for hex. Java shares the common set, has no \a or \v, and supports octal escapes (\0\377). JSON per RFC 8259 has the smallest set: \", \\, \/, \b, \f, \n, \r, \t, and \u00xx. Output from one is not always valid in another.

Need to reverse the operation?

Decode existing C# escape sequences back to plain text, or compare with Java and JavaScript escape behaviour.

Frequently Asked Questions

Verbatim @-strings vs regular strings — when do I escape?

Regular C# strings ("...") interpret backslash sequences, so a Windows path needs every backslash doubled. Verbatim strings (@"...") treat backslashes literally, so the same path stays as @"C:\Users\admin". The only escape inside a verbatim string is doubling the double quote ("") to embed it. This tool produces regular-string output — for verbatim, you can usually paste the raw value directly.

Does it escape Unicode?

No — non-ASCII characters are passed through unchanged because C# source files are UTF-8 by default and accept literal Unicode. If your project enforces ASCII-only source (a legacy convention), use \uXXXX or \xN[N..] escapes manually. Modern C# projects rarely need this.

Do I need to escape single quotes?

Not inside C# string literals — a single quote is just an ordinary character there. You only escape ' inside char literals ('a'). The tool follows that rule and leaves single quotes alone in string output.

What about $-interpolated and @-interpolated strings?

In a $-interpolated string ($"Hello {name}"), curly braces have meaning — to embed a literal brace, double it: {{ or }}. The escape transformation produced by this tool does not double braces, so paste output into a non-interpolated string or escape braces manually if you target $"".

How does this differ from C#'s System.Web.HttpUtility.JavaScriptStringEncode?

JavaScriptStringEncode targets JavaScript string literals — it escapes Unicode, surrogate pairs, and certain HTML-sensitive characters. The .NET escape tool here targets C# itself: backslash, double quote, and the standard C# control-character escapes. The two operate on different parsers and produce different output.

Can I use it for VB.NET?

VB.NET strings use a different convention — double quotes are escaped by doubling them ("") and there is no backslash escape in VB string literals. You would substitute \"" for the doubled-quote convention. This tool produces C#-style output; for VB.NET prefer doubled-quote-only escaping.

Are tabs and newlines preserved as escape sequences?

Yes. Real tab characters become \t, line feeds become \n, carriage returns become \r, and form feed / backspace become \f / \b. The output is a single-line C# string literal you can paste directly into source code without breaking compilation.

Is the input sent to a server?

No. The escape transformation runs in JavaScript inside your browser. C# string content often includes connection strings, secrets, or proprietary algorithms — none of it leaves your device. Verify in DevTools Network tab.

.NET Escape Online — Escape Strings for C#/VB