Search code examples
clojure

Turning a list of strings into a single string in clojure


For example, let's say I have a list

'("The" " " "Brown" " " "Cow")

I want to turn this into

"The Brown Cow" 

Is there a command in clojure that does this?


Solution

  • As Chris mentioned you can just use clojure.string/join

    another way without using a library (assuming you don't want any spaces.) is:

    (reduce str '("The" " " "Brown" " " "Cow"))
    

    will return

    "The Brown Cow"
    

    str takes a list of things and turns them into one string. You can even do this: (str "this is a message with numbers " 2 " inside")