Is there a function that joins a string into a delimited string?

N.N. picture N.N. · Oct 21, 2012 · Viewed 8.2k times · Source

Is there a function in Emacs Lisp that does the opposite of split-string, i.e. joins the elements of a list into string delimited by a given delimiter? In other words, is there a function that given a list, e.g. ("foo" "bar" "baz"), and a delimiter, e.g. ", ", returns that list as a string delimited by that delimiter, e.g. "foo, bar, baz".

Common Lisp seems to have such a function but the function with the same name in Emacs Lisp, format, is a wholly different function.

Answer

Volker Stolz picture Volker Stolz · Oct 21, 2012

I think you are looking for mapconcat:

mapconcat applies function to each element of sequence: the results, which must be strings, are concatenated. Between each pair of result strings, mapconcat inserts the string separator. Usually separator contains a space or comma or other suitable punctuation.