C# String Encoder
Escape special characters for safe use in C# string literals, or decode escaped strings back to plain text
Paste raw text, get a properly escaped C# string literal — regular, verbatim, or raw format. Encode special characters like quotes, backslashes, and control chars in one click, or decode an escaped string back to readable text. And everything runs in your browser. Nothing gets uploaded.
How It Works
The encoder scans your input character by character. Quotes become \", backslashes become \\, and control characters like newlines turn into \n. For verbatim strings, quotes are doubled instead. Raw strings need no escaping at all — the tool just wraps your text in triple-quote delimiters. Decoding reverses the whole process.
Examples
SQL query with quotes and backslashes
Embedding a SQL statement inside a C# regular string
SELECT * FROM users WHERE name = "O'Brien" AND path = 'C:\data\'
SELECT * FROM users WHERE name = \"O'Brien\" AND path = 'C:\\data\\'
JSON template with nested quotes
When you need to hardcode a JSON snippet as a C# string constant — common in unit tests and API mocks
{"name": "Alice", "role": "admin"}
{\"name\": \"Alice\", \"role\": \"admin\"}
File path for verbatim string
Windows file paths are the classic verbatim string use case — no more double-backslash headaches
C:\Users\Admin\Documents\report "final".docx
C:\Users\Admin\Documents\report ""final"".docx
Who Uses This
Embedding SQL, JSON, regex patterns, or file paths inside string literals without manual escaping.
Building test fixtures with hardcoded response bodies — escaped correctly the first time.
Generating escaped code examples for blog posts and documentation without typos.
Converting legacy strings between regular and verbatim formats during codebase upgrades.
Common Mistakes
A single \ in a regular string starts an escape sequence. C:\new becomes a newline, not a path. Use verbatim strings for paths or double every backslash.
In verbatim strings, \" doesn’t work — you need "" to embed a quote. In regular strings, "" is two empty strings concatenated, not an escaped quote. Pick one format and stick with it.
Pasting a string that’s already escaped and encoding it again turns \\n into \\\\n. If your input already has escape sequences, decode it first, then re-encode if you need a different format.
Technical Details
- Processing: 100% client-side — nothing leaves your browser
- Browser Support: Chrome, Firefox, Safari, Edge
- String Types: Regular, Verbatim (@), Raw (C# 11+)
- Unicode: Full support for BMP (\uXXXX) and supplementary (\UXXXXXXXX) characters
- Output: Copy to clipboard or download as .cs file
Frequently Asked Questions
What characters does C# string encoding escape?
For regular strings: double quotes, backslashes, and control characters like \n, \t, \r, \b, \f, \0, \a, and \v. With unicode mode on, anything above ASCII 127 gets converted to \uXXXX or \UXXXXXXXX too.
What’s the difference between regular, verbatim, and raw strings?
Regular strings use backslash escapes — \" for quotes, \\ for backslashes. Verbatim strings (prefixed with @) treat backslashes as-is and double up quotes instead: "". Raw strings use triple quotes and don’t need any escaping at all. They showed up in C# 11.
Can I convert between string types?
Yes. Decode the string in its current format, switch to a different string type, and encode again. For example, paste a regular escaped string, hit Decode, change to verbatim, then hit Encode. The tool handles the translation.
Is my code safe? Does anything get uploaded?
Nothing gets uploaded. The entire encoder runs in JavaScript inside your browser. No server calls, no analytics on your input, no storage. Disconnect your internet and it still works.
How do I handle emoji and special Unicode in C# strings?
Turn on the Unicode Escaping toggle. Characters above ASCII 127 get converted to \uXXXX escape sequences. Emoji and characters outside the Basic Multilingual Plane use the longer \UXXXXXXXX format with 8 hex digits. Or just use raw strings in C# 11+ where no escaping is needed.