Adam Sznajder
Adam Sznajder

Reputation: 9206

Concatenation of the strings vector in Clojure

I would like to concatenate strings stored in a vector. For example if I have ["a" "b" "c"] in the vector I would like to get as a result "abc".

Upvotes: 17

Views: 12770

Answers (3)

dsm
dsm

Reputation: 10393

This is one of the ways Clojure's reduce can be used. Note the session at Clojure's REPL:

[dsm@localhost:~]$ clj
Clojure 1.4.0
user=> (reduce str ["a" "b" "c"])
"abc"
user=> 

Upvotes: 6

mtyaka
mtyaka

Reputation: 8850

You can use apply with the str function:

(apply str ["a" "b" "c"])

Upvotes: 34

Sergey
Sergey

Reputation: 11908

You can use clojure.string join function for that

(clojure.string/join ["a" "b" "c"])

Upvotes: 20

Related Questions