在 Python 中,我可以添加前缀 r
到字符串文字(原始字符串)以告诉解释器不要翻译字符串中的特殊字符:
>>> r"abc\nsdf#$%\^"
r"abc\nsdf#$%\^"
有没有办法在 Clojure 中做同样的事情?
最佳答案
Clojure 字符串是 Java 字符串,读者不会对其解释添加任何重要内容。 The reader page只是说“支持标准的 Java 转义字符。”
你可以逃脱\
尽管:
user> (print "abc\\nsdf#$%\\^")
abc\nsdf#$%\^
这只会影响读取器读取的字符串文字,因此如果您从文件中读取字符串,则读取器永远不会看到它们:
user> (spit "/tmp/foo" "abc\\nsdf#$%\\^")
nil
user> (slurp "/tmp/foo")
"abc\\nsdf#$%\\^"
user> (print (slurp "/tmp/foo"))
abc\nsdf#$%\^nil
user>
所以,我认为基本的答案是否定的。
关于clojure - clojure 有原始字符串吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11043318/