6
$\begingroup$

I have a list:

lis = {{"abc","def","ghi"},{"jkl","mno"}}

and wish to get:

res = {"abc def ghi","jkl mno"}

This:

Table[StringJoin[lis[[i]]], {i, Length[lis]}]

doesn't produce the desired " " between the original elements in lis. As always, thanks for suggestions!

$\endgroup$
16
$\begingroup$

You can use StringRiffle:

StringRiffle /@ lis

{"abc def ghi", "jkl mno"}

$\endgroup$
8
$\begingroup$

Use Riffle

lis = {{"abc", "def", "ghi"}, {"jkl", "mno"}};

StringJoin[Riffle[#, " "]] & /@ lis

(* {"abc def ghi", "jkl mno"} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.