gschmidt Posted April 14, 2015 Posted April 14, 2015 Hi, How can I convert a List to a comma delimited string? (setq List '((a b c d e f))) -> (setq result "a, b, c, d, e, f") Quote
pBe Posted April 14, 2015 Posted April 14, 2015 Are those symbols as elements? i.e variable name, not as string Quote
pBe Posted April 14, 2015 Posted April 14, 2015 a = stringbcdef = float Sorry dude, I don't get it Quote
gschmidt Posted April 14, 2015 Author Posted April 14, 2015 Ok sorry maybe is this better? (setq List '((Anchor1 10 10 6.5 900 600 500 400))) -> (setq result "Anchor1, 10, 10, 6.5, 900, 600, 500, 400") I want to write the List as a row to a CSV file Quote
Tharwat Posted April 14, 2015 Posted April 14, 2015 Be careful , you are assigning a list to the function . Maybe ? (setq lst '((Anchor1 10 10 6.5 900 600 500 400))) (mapcar '(lambda (l) (apply 'strcat (mapcar '(lambda (x) (if (eq (type x) 'SYM) (strcat (vl-princ-to-string x) ",") (strcat (rtos x 2) ","))) l)) ) lst ) Quote
gschmidt Posted April 14, 2015 Author Posted April 14, 2015 It's just an example name, i'll give it a try...thanx Quote
gschmidt Posted April 14, 2015 Author Posted April 14, 2015 What happens if the List has NIL values? I want to convert NIL values to an empty string: " " Quote
Tharwat Posted April 14, 2015 Posted April 14, 2015 What happens if the List has NIL values?I want to convert NIL values to an empty string: " " (setq lst '((Anchor1 10 nil 10 6.5 900 600 500 400))) (mapcar '(lambda (l) (apply 'strcat (mapcar '(lambda (x) (cond ((eq (type x) 'SYM) (strcat (vl-princ-to-string x) ",")) ((numberp x) (strcat (rtos x 2) ",")) ((not x) " ,") ) ) l)) ) lst ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.