Pregunta

Possible Duplicate:
How do I make a string with a " character in it? (Java)

I am having trouble printing a string like this in java System.out.println("this is a "test""); How can I go about this?

¿Fue útil?

Solución

This is what you are looking for:

System.out.println("this is a \"test\"");

The \ is called the escape character.

It is used to embed special characters into a String literal.

\n = newline

\t = tab

\f = form feed

\r = carriage return

\" = double quote

\\ = backslash

this is just a few of the special characters you can insert with an escape sequence.

Otros consejos

The way you escape special characters in Java is using \. E.g. this ("\\") is how you return \ and this ("\"") is how you return ".

This is how you may implement your example:

System.out.println("this is a \"test\"");

escape the quote

System.out.println("this is a \"test\"");

You must escape the " characters in Java

System.out.println( "this is a \"test\"");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top