UTILS.
100% in-browser
🔤

Source-Code String Escaper / Unescaper

Escape or unescape text as a string literal for Java, C#, C/C++, JavaScript, JSON, SQL, or XML/HTML — one tool, seven languages, all in-browser.

— output appears here —

About this tool

The Source-Code String Escaper / Unescaper turns arbitrary text into a safe string literal for the programming language you pick, or reverses a literal back into plain text. It is the quickly-needed helper for pasting a multi-line block, a path, or text containing quotes into source code without breaking it. Everything runs in your browser as a pure string transform; nothing is uploaded.

Each language uses its own escape table. JavaScript and JSON escape backslash, double-quote, and the control set (\n \r \t \b \f) and emit \uXXXX for other control or non-ASCII characters. Java uses the same C-style set with \uXXXX over UTF-16 code units. C, C++ and C# add \0 \a \v and \xHH for bytes. SQL doubles single quotes ('' ), the ANSI-standard way to embed a quote in a string literal. XML/HTML replaces & < > " ' with &amp; &lt; &gt; &quot; &apos; and emits &#nnn; for other non-printable characters.

Unescape reverses the same tables: it parses \n, \t, \xHH, \uXXXX and \u{...} sequences for the C-family languages, collapses doubled quotes for SQL, and resolves named and numeric (&#nnn; / &#xHH;) entities for XML/HTML. Choose the target language and whether to escape or unescape. This tool is broader than the JSON-only and HTML-only escapers — it covers all seven targets in one place.

Frequently asked questions

Which languages are supported?
JavaScript, JSON, Java, C#, C/C++, SQL, and XML/HTML. Each uses its own escape rules — for example \uXXXX for JavaScript/Java/JSON, \xHH and \0 for C-family, doubled single quotes for SQL, and named plus numeric entities for XML/HTML.
How does it handle non-ASCII characters?
For JavaScript, JSON, and Java it emits \uXXXX (with surrogate pairs for characters above U+FFFF). C and C# can use \xHH for bytes. XML/HTML leaves printable Unicode as-is and only escapes the five markup characters plus control codes as &#nnn;.
Can it reverse an escaped string?
Yes. Switch the direction to Unescape and it parses the language's escape sequences back to plain text — \uXXXX, \xHH, \u{...}, doubled SQL quotes, and named or numeric HTML/XML entities are all decoded.
How is this different from the JSON or HTML escaper?
Those handle a single format. This tool covers seven language targets in one place with their distinct escape tables, so you can escape the same text for a Java literal, a SQL string, or an XML attribute without switching tools.

More tools