How to convert a clojure keyword into a string?

Viewed 36328

In my application I need to convert clojure keyword eg. :var_name into a string "var_name". Any ideas how that could be done?

5 Answers

It's not a tedious task to convert any data type into a string, Here is an example by using str.

(defn ConvertVectorToString []
 (let [vector [1 2 3 4]]
 (def toString (str vector)))
  (println toString)
  (println (type toString)
(let [KeyWordExample (keyword 10)]
 (def ConvertKeywordToString (str KeyWordExample)))
  (println ConvertKeywordToString)
  (println (type ConvertKeywordToString))

(ConvertVectorToString) ;;Calling ConvertVectorToString Function

Output will be:
1234
java.lang.string
10
java.lang.string

This will also give you a string from a keyword:

(str (name :baz)) -> "baz"
(str (name ::baz)) -> "baz"
Related