clojure有原始字符串吗? [英] Does clojure have raw string?

查看:187
本文介绍了clojure有原始字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python中,我可以将一个 r 前缀到字符串文字(原始字符串),以便解释器不会在字符串中翻译特殊字符:

In Python, I can prefix an r to a string literal (raw string) to tell the interpreter not translate special characters in the string:

>>> r"abc\nsdf#$%\^"
r"abc\nsdf#$%\^"

有没有办法在Clojure中做同样的事情?

Is there a way to do the same thing in Clojure?

推荐答案

Clojure字符串是Java字符串读者不会对其解释增添任何重要的东西。 读者页面只是说支持标准Java转义字符。

Clojure strings are Java strings and the reader does not add anything significant to their interpretation. The reader page just says "standard Java escape characters are supported."

您可以逃避 \

user> (print "abc\\nsdf#$%\\^")
abc\nsdf#$%\^

这只影响读者阅读的字符串文字,所以如果你从文件读取字符串,读者永远都不会看到他们:

This only affect string literals read by the reader, so if you read strings from a file the reader never sees them:

user> (spit "/tmp/foo" "abc\\nsdf#$%\\^")
nil
user> (slurp "/tmp/foo")
"abc\\nsdf#$%\\^"
user> (print (slurp "/tmp/foo"))
abc\nsdf#$%\^nil
user> 

所以,我认为基本答案是否定的。

So, I think the basic answer is no.

这篇关于clojure有原始字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆