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

查看:140
本文介绍了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天全站免登陆