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.
The CONCATENATE function joins two text strings into one text string.
The join() method takes all items in an iterable and joins them into one string. A string must be specified as the separator.
Split is used to break a delimited string into substrings. You can use either a character array or a string array to specify zero or more delimiting characters or strings. If no delimiting characters are specified, the string is split at white-space characters.
In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect.
I think you are looking for mapconcat:
mapconcatapplies function to each element of sequence: the results, which must be strings, are concatenated. Between each pair of result strings,mapconcatinserts the string separator. Usually separator contains a space or comma or other suitable punctuation.
Emacs has string-join since 24.4 as part of subr-x.el:
(eval-when-compile (require 'subr-x)) (string-join '("one" "two" "three") ", ") ; ==> "one, two, three" subr-x.el contains also other useful (string manipulation) functions - from the 24.4 release notes:
New library subr-x.el for misc helper functions hash-table-keys hash-table-values string-blank-p string-empty-p string-join string-reverse string-trim-left string-trim-right string-trim string-remove-prefix string-remove-suffix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With