问题
My string has double quotes in it, in C#
I would do:
string blah = @"this is my ""text";
how would I do that in Java?
回答1:
No. Such a feature is not available in Java.
From the Sun docs:
When an escape sequence is encountered in a print statement, the compiler interprets it accordingly. For example, if you want to put quotes within quotes you must use the escape sequence, \", on the interior quotes. To print the sentence
She said "Hello!" to me.
you would write
System.out.println("She said \"Hello!\" to me.");
回答2:
There is nothing like it currently, but it is a "Fix understood" request for enhancement.
- Bug ID 4472509: Add support for vertabim(sic) string literals
If added, this feature would allow such string literals:
String qry = @"
SELECT
a.name, b.number
FROM
User a, Data b
WHERE
a.name = "James"
AND
a.id = b.id
";
Some of the comments reject this principally on the fact that it's a syntactic sugar, but obviously there's high demand for it, so it's possible that we'll see this someday.
来源:https://stackoverflow.com/questions/2018556/does-java-have-the-character-to-escape-string-quotes