Java 字符串引号分隔符

发布于 2024-10-08 15:59:40 字数 182 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

血之狂魔 2024-10-15 15:59:41

实现此目的的唯一方法是将字符串放入其他文件中并从 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.

手心的海 2024-10-15 15:59:41

目前不可能,将来也可能不可能。

如果您可以向我们提供您正在寻找此类功能的内容和原因,我们肯定可以建议更多替代方案

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

半步萧音过轻尘 2024-10-15 15:59:40

不,没有这样的选择。对不起。

No, there is no such option. Sorry.

少女净妖师 2024-10-15 15:59:40

不 - 例如,没有什么比 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 :(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文