开发者

How can I convert a keyword to a string? [duplicate]

This question already has answers here: How to convert a clojure keyword into a string? (5 answers) Closed 7 years ago.

In clojure, what is the idiomatic way to convert a keyword:

:some-keyword

to a string:

"some-keyword"
开发者_如何学编程


use name to do this:

user=> (name :some-keyword)
"some-keyword"


As Alex Ott mentionned, name is the best function for this, clojure.contrib also has a function you can call on any type: as-str which does this too:

(str :foo :bar)     ;;=> ":foo:bar"
(as-str :foo :bar)  ;;=> "foobar" 

See http://clojure.github.com/clojure-contrib/string-api.html#clojure.contrib.string/as-str

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜