Jump to content

Recommended Posts

Posted

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")

Posted

Are those symbols as elements? i.e variable name, not as string

Posted
a = string

bcdef = float

 

Sorry dude, I don't get it :?

Posted

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

Posted

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
      )

Posted

It's just an example name, i'll give it a try...thanx

Posted

What happens if the List has NIL values?

I want to convert NIL values to an empty string: " "

Posted
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
      )

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...