Does Java have the '@' character to escape string quotes?

∥☆過路亽.° 提交于 2019-12-28 17:56:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!