String Escape / Unescape

Escape or unescape text for JavaScript, JSON, Java, Python, C, C#, SQL, regular expressions, shell commands, CSV and XML string literals.

Processed on your device. Files are not uploaded

How to escape a string for code

  1. Paste your text

    Paste or type it into the box, or press Try an example.

  2. Choose the language

    JavaScript, JSON, Java, Python, C, C#, SQL, regex, shell, CSV or XML.

  3. Copy or download

    Paste the escaped string into your code.

Worked example

This is what String Escape / Unescape gives for its own sample values. Open the tool above and change anything to try your own.

Text

He said "hi"
	It's a back\slash
Direction
Escape
For
JavaScript
Quote style
Double quotes

Result

He said \"hi\"\n\tIt's a back\\slash

About String Escape / Unescape

Make text safe to put inside a string literal in your language, or reverse it. Quotes, backslashes, line breaks, tabs and control characters are handled the way each language expects.

FAQs

Does it add the surrounding quotes?

No. It escapes the inside, except for shell, where the text is wrapped in single quotes because that is the only safe form.

Which quote style should I pick?

Choose the quote your string uses, so that quote gets a backslash.

Is this enough to stop SQL injection?

No. Use parameterised queries. Escaping is for building text, not for protecting a database.

Related tools