Java 字符串引号分隔符
Java 有没有办法在字符串的开头和结尾使用特殊的分隔符来避免必须反斜杠该字符串中的所有引号?
即不必这样做:
String s = "Quote marks like this \" are just the best, here are a few more \" \" \""
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 \" \" \""
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实现此目的的唯一方法是将字符串放入其他文件中并从 Java 读取它。例如资源包。
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.
目前不可能,将来也可能不可能。
如果您可以向我们提供您正在寻找此类功能的内容和原因,我们肯定可以建议更多替代方案
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
不,没有这样的选择。对不起。
No, there is no such option. Sorry.
不 - 例如,没有什么比 C# 的逐字字符串文字或 Groovy 的斜杠字符串更好的了。
另一方面,这是将来可能会包含的功能。这并不需要对类型系统进行任何根本性的改变。不过,我会非常惊讶于它这么晚才进入 Java 7,而且我还没有看到任何关于它会出现在 Java 8 中的建议......所以你'等待很长时间:(
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 :(