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

后端 未结 2 1816
情深已故
情深已故 2020-12-10 14:37

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?

相关标签:
2条回答
  • 2020-12-10 14:52

    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.

    0 讨论(0)
  • 2020-12-10 15:00

    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.");
    
    0 讨论(0)
提交回复
热议问题