简体   繁体   English

Java字符串引号分隔符

[英]Java String quote delimiter

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? 在Java中是否有任何方法在String的开头和结尾使用特殊的分隔符,以避免必须反斜杠该String中的所有引号?

ie not have to do this: 即不必这样做:

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

No, there is no such option. 不,没有这样的选择。 Sorry. 抱歉。

No - there's nothing like C#'s verbatim string literals or Groovy's slashy strings, for example. 不 - 没有什么比C#的逐字字符串文字或Groovy的斜线字符串更好的了。

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 :( 我很惊讶巨大的它,使之成为Java 7的这一晚了一天,虽然,我还没有看到任何建议,这将是在Java中8 ...所以你在漫长的等待是: (

The only way to achive this is to put your strings in some other file and read it from Java. 实现此目的的唯一方法是将您的字符串放在其他文件中并从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 如果你能告诉我们你为什么以及为什么要享受这种功能,我们可以确定一些更多的选择

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM