Java / .Net Escape / Unescape
Escapes or unescapes a Java or .Net string, replacing characters that could prevent compiling with their escape sequences.
Result
Java and .Net string escaping explained
Why escape?
A string literal in Java, C#, VB.Net or Kotlin is delimited by double quotes. A literal double quote, a backslash or a line break inside the value would end the literal early or confuse the compiler, so those characters are written as escape sequences, a backslash followed by a letter or a code. This tool turns raw text into something you can paste between quotes in your source code, and turns an escaped literal back into readable text.
Rules applied by this tool
| Character | Escaped as | Notes |
|---|---|---|
| Backspace (U+0008) | \b | |
| Newline (U+000A) | \n | |
| Tab (U+0009) | \t | |
| Carriage return (U+000D) | \r | |
| Form feed (U+000C) | \f | |
| Double quote | \" | |
| Backslash | \\ | Must be handled first, otherwise the other sequences would be escaped twice. |
| Single quote | \' | Only with the "Also escape single quotes" option. Required in char literals ('\''), optional in string literals. |
| Other control characters (U+0000–U+001F, U+007F) | \u0000 … \u001F | Always, since they are invisible. |
| Non-ASCII characters (é, 日, 😀) | \u00E9, \u65E5, \uD83D\uDE00 | Only with the "\uXXXX" option. Characters outside the Basic Multilingual Plane become a surrogate pair. |
Before / after
| Input | Escaped output |
|---|---|
He said "hi" | He said \"hi\" |
C:\Users\tom | C:\\Users\\tom |
| Two lines separated by a line break | line one\nline two |
Café (with the \uXXXX option) | Caf\u00E9 |
Unescaping
The unescape button decodes \b \n \t \r \f \" \' \\ \0, octal escapes (\101 = A, Java only) and \uXXXX sequences. Java processes \u escapes before lexing, so \u0022 is a real double quote that terminates a literal, a classic trap. C# additionally supports \x (variable length) and \U00XXXXXX escapes, and verbatim strings (@"C:\path") where only "" needs escaping; the tool targets the common escape syntax shared by both languages.
In code
// Java (Apache Commons Text)
StringEscapeUtils.escapeJava("Tab\there"); // Tab\\there
StringEscapeUtils.unescapeJava("Tab\\there");
// Java 15+: text blocks avoid most escaping
String json = """
{"name": "Tom \\"the cat\\""}
""";
// C#: use verbatim or raw string literals
string path = @"C:\Users\tom";
string raw = """He said "hi" """;