Java String use quotes without escape character

后端 未结 3 997
北恋
北恋 2021-01-12 12:49

I know that it is possible to write double quotes in Java strings by putting \\ symbol before them. But if double quotes are used a lot in a string, is there a

相关标签:
3条回答
  • 2021-01-12 13:13

    No, there is no such way to write a String literal with unescaped quotes.

    You can write the text externally and load it at runtime.

    0 讨论(0)
  • 2021-01-12 13:20

    There is no way to escape all subsequent double quotes in code (that I know of). But, I recommend against hard-coding String literals. Instead, I suggest you use a ResourceBundle (or even Properties). One benefit being you don't have to escape String(s) you read in that way.

    0 讨论(0)
  • 2021-01-12 13:30

    You can't. But if you are too lazy to escape each of the double quotes, there are some trick that can do that. For example:

    String quotes = "....................".replace(".","\"");
    System.out.println(quotes);
    

    output: """"""""""""""""""""

    0 讨论(0)
提交回复
热议问题