Java String quote delimiter

与世无争的帅哥 提交于 2020-02-03 05:46:13

问题


Is there any way in Java to use a special delimiter at the start and the end of a String to avoid having to backslash all of the quotes within that String?

i.e. not have to do this:

String s = "Quote marks like this \" are just the best, here are a few more \" \" \""

回答1:


No, there is no such option. Sorry.




回答2:


No - there's nothing like C#'s verbatim string literals or Groovy's slashy strings, for example.

On the other hand, it's the kind of feature which may be included in the future. It's not like it would require any fundamental changes in the type system. I'd be hugely surprised for it to make it into Java 7 this late in the day though, and I haven't seen any suggestions that it'll be in Java 8... so you're in for a long wait :(




回答3:


The only way to achive this is to put your strings in some other file and read it from Java. For instance a resource bundle.




回答4:


Its not possible as of now, May be NOT in future also.

if you can give us what and why you are loookng for this kind of feature we can defnitely Suggest some more alternatives



来源:https://stackoverflow.com/questions/4492189/java-string-quote-delimiter

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