Skip to content
100% local

Code string escaper

Turn pasted text into a string literal for C, Python, SQL, shell and 16 other languages — and back.

Input
Output

Code string escaper

Paste text and this tool turns it into a valid string literal for the language you pick — C, C++, C#, Java, JavaScript, TypeScript, Python, Go, Rust, PHP, Ruby, Swift, Kotlin, SQL, Shell, PowerShell, YAML, JSON, XML or CSV — or runs it in reverse to turn an escaped literal back into plain text. Every language escapes quotes, backslashes and newlines a little differently: syntax that's valid PHP single-quoted breaks as Python, and a bash double-quoted string doesn't behave like a PowerShell one with the same punctuation.

Pick a quote style to match what you're pasting into — single, double or backtick, where the language supports it; an unsupported combination, like a backtick string in C, falls back to the language's own default instead of producing invalid code. "Wrap result in quotes" adds or omits the surrounding quote characters. "Escape non-ASCII as \u sequences" turns accented letters and emoji into \uXXXX escapes for strict ASCII output; left off, they stay literal UTF-8. "Keep literal tabs" leaves tab characters as-is instead of writing the tab escape.

"Use multi-line literal instead of \n" switches multi-line text to the language's native multi-line form where one exists — a Python triple-quoted string, a JavaScript template literal, a PHP or Ruby heredoc, a bash quoted heredoc, a PowerShell here-string, or a YAML block scalar — so the result reads with real line breaks instead of a wall of \n. Languages without one (C, C++, C#, Go, Kotlin, JSON, XML, CSV) fall back to \n escapes.

Everything runs locally in your browser. The snippet you paste — a config value, a log line, user input you're hardening for a query — never leaves your device. Copy the result, download it as a .txt file, or send it into another tool to keep working.

FAQ

Which quote style should I pick?
Match whatever the surrounding code expects. Most C-family languages (C, C++, C#, Java, Go, Rust, Swift, Kotlin) only support double quotes for strings, so single or backtick silently falls back to double for those. JavaScript, TypeScript, Python, PHP and Ruby support more than one style, and PHP/Ruby single-quoted strings only escape a backslash and a quote — everything else, including tabs and newlines, stays completely literal.
What does "Use multi-line literal instead of \n" actually produce?
It swaps the usual \n-escaped single-line result for the language's native multi-line construct — a triple-quoted string in Python, a template literal in JavaScript/TypeScript, a heredoc in PHP, Ruby or bash, a here-string in PowerShell, or a block scalar in YAML — keeping real line breaks in the output. It only changes anything when the input has more than one line and the selected language has such a construct; otherwise it's a no-op.
Does unescaping detect the wrapping quotes automatically?
Yes. Paste an escaped literal — with or without its surrounding quotes — and the tool strips a matching wrapper (including a multi-line one, if present) before decoding. Unescaping is best-effort: an unrecognized escape sequence is kept as its literal character rather than rejected as an error.
Why doesn't every language get its own exact \u syntax?
To keep behavior predictable, non-ASCII escaping always writes a plain \uXXXX sequence (or, for XML, a numeric character reference by real code point). This matches JavaScript, Java, C# and JSON exactly; other languages accept it as UTF-16 input even where their own native syntax differs slightly, such as an astral character split across two escapes.
Is my code or text uploaded anywhere?
No. Escaping and unescaping run entirely in your browser — nothing you paste here is ever sent to a server.