jsonecho

Escapar Java

Prepara texto para insertarlo de forma segura en una cadena Java.

Cargando la herramienta...

Cómo usar Escapar Java

  1. Pega el texto.
  2. Copia el resultado.

Sobre Escapar Java

Genera la forma escapada que puedes pegar entre comillas en código Java.

What gets escaped

Backslash becomes \\, a double quote becomes \", newline \n, carriage return \r, tab \t, backspace \b, form feed \f. Other control characters turn into \uXXXX.

Preguntas frecuentes

Do I need to escape single quotes in a Java string?

Not inside a double quoted string, only inside a char literal. There is an option if you need it.

Why are my regex backslashes doubled?

Java escapes the backslash in the string first, and the regex engine then reads the result. A pattern for a digit, \d, has to be written "\\d" in the source.

How does this differ from the JavaScript escape?

Java does not escape single quotes by default and has no \v or \x escapes, so the output differs for a few characters.

Is there an easier way for long text?

From Java 15 on, text blocks with triple quotes let you paste multi-line text without escaping line breaks and quotes.

Más en Escape y texto

Todas las herramientas →