[英]What's the counterpart in Java of C#'s @ string literal?
C# has the @ string literal to flexibly handle escape characters in strings. C#有@ string文字来灵活处理字符串中的转义字符。 Is there anything like that in Java? Java中有类似的东西吗?
There isn't. 没有。 You'll need to escape your strings. 你需要逃避你的弦乐。
This is called a verbatim string literal. 这称为逐字字符串文字。
Java does not have such a feature. Java没有这样的功能。
If only I had a nickle for every time I need this in Java... 如果我每次在Java中需要这个时候只有一个镍币......
If you're doing a Regex operation consider Pattern.quote
as a replacement. 如果您正在进行正则表达式操作,请将Pattern.quote
视为替代。
Java supports path separators from UNIX which don't need to be escaped. Java支持UNIX中的路径分隔符,不需要转义。 eg 例如
"c:/my/file.txt"
works fine on windows (and unix if you have a directory called c:
) 在Windows上运行正常(如果你有一个名为c:
的目录,则运行unix)
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 ;) http://en.wikipedia.org/wiki/Backslash
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.