简体   繁体   中英

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" .

您可以使用带有str函数的apply

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

你可以使用clojure.string连接函数

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

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=> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM