CSharp Escape Unescape
Escape and unescape C# strings online. Convert special characters to C# escape sequences or decode them back instantly.
About
C# string literals require specific escape sequences for characters that conflict with the language syntax or represent non-printable control codes. A misplaced backslash or unescaped quotation mark causes compile-time error CS1010 or silent data corruption when writing to files and databases. This tool performs bidirectional conversion between raw text and C# escaped string content, handling all standard sequences defined in ECMA-334 including \uXXXX Unicode escapes for characters above U+007E. It processes \n, \t, \r, \0, \a, \b, \f, \v, \\, \", and \' in both directions.
The unescape parser uses a single-pass finite state machine to correctly resolve chained sequences without double-processing. Note: this tool handles regular string literals, not verbatim strings (prefixed with @) which use different escaping rules. Pro tip: when embedding JSON inside C# strings, escape the entire payload first, then verify the output compiles by checking for unmatched backslashes.
Formulas
The escape transformation applies a deterministic character mapping function E over each character c in the input string S:
Where map(c) is defined as a piecewise function:
The unescape operation U is the inverse: it scans for \ followed by a recognized suffix character and replaces the two-character sequence (or six-character \uXXXX) with the corresponding literal character. Order of processing matters: \\ must be resolved before single \ to prevent cascade errors.
Where S = input string, ci = character at index i, n = length of string, charCode = UTF-16 code unit value.
Reference Data
| Escape Sequence | Character | Unicode Code Point | Description |
|---|---|---|---|
| \' | ' | U+0027 | Single quotation mark |
| \" | " | U+0022 | Double quotation mark |
| \\ | \ | U+005C | Backslash |
| \0 | NUL | U+0000 | Null character |
| \a | BEL | U+0007 | Alert (bell) |
| \b | BS | U+0008 | Backspace |
| \f | FF | U+000C | Form feed |
| \n | LF | U+000A | New line (line feed) |
| \r | CR | U+000D | Carriage return |
| \t | HT | U+0009 | Horizontal tab |
| \v | VT | U+000B | Vertical tab |
| \uXXXX | Unicode | U+0000 to U+FFFF | Unicode escape (4 hex digits) |
| \UXXXXXXXX | Unicode | U+00000000 to U+0010FFFF | Unicode escape (8 hex digits, surrogate pairs) |
| \xN[N][N][N] | Unicode | U+0 to U+FFFF | Variable-length hex escape (1-4 digits) |