我有两个以逗号分隔的字符串,如下所示:
stringA "a,b,c,d"
stringB "w,x,y,z"
如何在 clojure 中合并字符串,如下所示:
stringResult "aw,bx,cy,dz"
注意: stringA 和 stringB 的逗号分隔值相同。
答案 0 :(得分:2)
如果以逗号分隔的项目可以包含多个字符:
(defn combine
[stringA stringB]
(let [seqA (clojure.string/split stringA #",")
seqB (clojure.string/split stringB #",")
combined (map str seqA seqB)]
(clojure.string/join "," combined)))
答案 1 :(得分:0)
(.replace (apply str (map str stringA stringB)) ",," ",")
;=> "aw,bx,cy,dz"
请参阅下面的A. Webb评论。