Java 有“@”吗?转义字符串引号的字符?
我的字符串中有双引号,在 C# 中我会这样做:
string blah = @"this is my ""text";
在 Java 中我将如何做到这一点?
My string has double quotes in it, in C#
I would do:
string blah = @"this is my ""text";
how would I do that in Java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不可以。Java 中没有这样的功能。
来自 Sun docs:
遇到转义序列时在 print 语句中,编译器会相应地解释它。例如,如果您想在引号内放置引号,则必须在内部引号上使用转义序列 \"。要打印
您将编写的句子
No. Such a feature is not available in Java.
From the Sun docs:
When an escape sequence is encountered in a print statement, the compiler interprets it accordingly. For example, if you want to put quotes within quotes you must use the escape sequence, \", on the interior quotes. To print the sentence
you would write
目前还没有类似的东西,但这是一个“修复理解”的增强请求。
如果添加,此功能将允许这样的字符串文字:
一些评论拒绝这一点,主要是因为它是一种语法糖,但显然对它的需求很高,所以有一天我们可能会看到它。
There is nothing like it currently, but it is a "Fix understood" request for enhancement.
If added, this feature would allow such string literals:
Some of the comments reject this principally on the fact that it's a syntactic sugar, but obviously there's high demand for it, so it's possible that we'll see this someday.
是*(自 2019 年 9 月起),但它使用不同的语法。 “””(三个双引号)。
*在最近的java版本中(预览版+13,生产就绪+15),大多数等效可以通过java文本块实现。
https://docs.oracle.com/en/java/ javase/13/text_blocks/index.html
Yes* (since September 2019) but it used different sintax. “”” (three double-quote marks).
*In more recent java versions (+13 in preview, +15 as production ready), mostly equivalent can be achieved with the java text blocks.
https://docs.oracle.com/en/java/javase/13/text_blocks/index.html