문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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\"");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top