List to String

See also String to List

Function Syntax (LM:lst->str <lst> <del>)
Current Version 1.0
Donate
Arguments
Symbol Type Description
lst List List of strings to concatenate
del String Delimiter string to separate each list item
Returns
Type Description
String A concatenation of the strings in 'lst' separated by the delimiter 'del'

Function Description

This function will return the concatenation of all strings in a given list, separating each list item using the supplied delimiter string.

This functionality is more clearly demonstrated by the example function call shown below.

The converse of this function is String to List.

Recursive Version

Select all
;; List to String  -  Lee Mac
;; Concatenates each string in a supplied list, separated by a given delimiter
;; lst - [lst] List of strings to concatenate
;; del - [str] Delimiter string to separate each item

(defun LM:lst->str ( lst del )
    (if (cdr lst)
        (strcat (car lst) del (LM:lst->str (cdr lst) del))
        (car lst)
    )
)

Iterative Version

Select all
;; List to String  -  Lee Mac
;; Concatenates each string in a supplied list, separated by a given delimiter
;; lst - [lst] List of strings to concatenate
;; del - [str] Delimiter string to separate each item

(defun LM:lst->str ( lst del / str )
    (setq str (car lst))
    (foreach itm (cdr lst) (setq str (strcat str del itm)))
    str
)

Example Function Call

_$ (LM:lst->str '("1" "2" "3" "4" "5") ",")
"1,2,3,4,5"

See also String to List

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010