String Escape
Escape or unescape strings for Java, C#, JavaScript, Python, JSON, SQL, regular expressions and CSV.
Runs in your browser. Nothing is uploaded.
How to use the String Escape
- Paste your text into the left box, or press Load example.
- Choose the language the string will be used in, such as Java, C#, JavaScript, Python, JSON, SQL, regex or CSV.
- Choose Escape to make text safe inside a string literal, or Unescape to turn escapes back into normal text.
- The result appears on the right as you type. Invalid escape sequences are reported with their position.
- Copy the result into your code or query.
Make any text safe inside a string literal
Copying a file path, an error message, a JSON snippet or a line of user-facing text into code often
breaks it. One unescaped quote ends the string early, a backslash turns \t into a tab, and a line break
isn’t allowed at all. This tool rewrites your text with the right escape sequences for the language
you’re writing in, and can reverse the process to read an escaped string.
Supported formats
- Java, C#, JSON: backslash escapes for
",\, new lines, tabs and control characters - JavaScript / TypeScript: as above, plus single quotes and the line separator characters that can break older engines
- Python: backslash escapes including single quotes, with
\xfor control characters - SQL: single quotes doubled, as in
'O''Brien' - Regular expressions: symbols with special meaning, such as
. * + ? ( ) [ ] { } | ^ $, are escaped so they match literally - CSV: a field containing commas, quotes or line breaks is wrapped in double quotes with inner quotes doubled
Unescape too
Switch the direction to Unescape to decode a string from a log, an error message or source code
back into readable text, including \u00e9-style Unicode escapes. If a sequence isn’t valid for the
chosen language, such as \q, you’ll see where it is.
A note on security
Escaping is not a substitute for parameterised queries or proper output encoding. When values come from users, use your database driver’s placeholders and your templating system’s escaping. This tool is for writing literals by hand. Everything runs in your browser.
Frequently asked questions
What does escaping a string mean?
Inside a string literal, some characters have a special meaning. A quote ends the string, and a backslash starts an escape sequence. Escaping replaces them with safe sequences, such as \" for a quote and \\ for a backslash, so the language reads them as ordinary characters.
Why do languages escape differently?
Java, C#, JavaScript, Python and JSON all use backslash escapes, with small differences. JavaScript and Python also escape single quotes, and Python writes control characters as \x41 rather than \u0041. SQL instead doubles single quotes, regular expressions escape special symbols like . * and ?, and CSV wraps fields containing commas or quotes in double quotes.
Should I escape user input to prevent SQL injection?
No. Use parameterised queries (prepared statements) for anything users can type. Escaping by hand is easy to get wrong. This tool is for writing literal values in your own scripts and queries.
Can I paste a whole Windows path?
Yes. Every backslash is doubled for C-style languages, so C:\Users becomes C:\\Users. In C# you could also use a verbatim string (@"C:\Users") instead.
Is my text uploaded?
No. Escaping happens entirely in your browser.
Tutorials
How to put a Windows file path into a Java or C# string
Escape backslashes and quotes in a Windows path so it works as a string literal in Java, C#, JavaScript or Python.