Java 中 C# 的 @ 字符串文字对应的是什么?
C#有@stringliteral来灵活处理字符串中的转义字符。 Java中有类似的东西吗?
C# has the @ string literal to flexibly handle escape characters in strings. Is there anything like that in Java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没有。你需要转义你的字符串。
There isn't. You'll need to escape your strings.
这称为逐字字符串文字。
Java没有这样的功能。
This is called a verbatim string literal.
Java does not have such a feature.
如果每次我在 Java 中需要这个时我都有一个缺口就好了...
如果您正在执行正则表达式操作,请考虑使用
Pattern.quote
作为替代品。If only I had a nickle for every time I need this in Java...
If you're doing a Regex operation consider
Pattern.quote
as a replacement.Java 支持 UNIX 中的路径分隔符,无需转义。例如,
在 Windows 上工作正常(如果您有一个名为
c:
的目录,则在 unix 上)选择使用
\
而不是/
作为路径分隔符就像之前或之后的几乎所有其他操作系统一样,这是我最讨厌的。 ;) http://en.wikipedia.org/wiki/BackslashJava supports path separators from UNIX which don't need to be escaped. e.g.
works fine on windows (and unix if you have a directory called
c:
)The chose to use
\
rather than/
as a path separator like just about every other operating system before or since, is a pet hate of mine. ;) http://en.wikipedia.org/wiki/Backslash