OK. Let we see which proposed solution produces correct result.
@saifumk8asked for:
I need to convert string as a list in Lisp.
I have this:
"1000,1947958.861,1165020.235,588.929,B BOC"
I need like this
(1000 1947958.861 1165020.235 588.929 B BOC)
@doaiena proposed using Lee Mac's http://www.lee-mac.com/stringtolist.html
Applied to test string it produces:
(LM:str->lst str "," )
("1000" "1947958.861" "1165020.235" "588.929" "B BOC")
It just have to be translated to meaningful data type.
Here using "read" my create an error
(mapcar 'read (LM:str->lst str "," ))
(1000 1.94796e+006 1.16502e+006 588.929 B)
@phanaem proposed
(read (strcat "(" (vl-string-translate "," " " str) ")"))
(1000 1.94796e+06 1.16502e+06 588.929 B BOC)
It is a solution to what @saifumk8 asked, but question is what is a final string in a list "B BOM" or "BOM".
So here is my solution that takes into account data type of particular list element.
(defun read_to_lst (str delimiter clear_spaces / ret poz *error*)
;converts delimited string into a list and respects data types
;hak_vz (24.11.2019)
;if string includes unwanted empty spaces, they can be cleared by setting switch "clear_spaces" to true
;this option may occur when reading strings from file or manually prepared data set
(defun *error* ( ) (princ "\nThere was some error") (princ))
(defun clear_empty_spaces (str)
(setq str (vl-string-trim " " str))
(while (vl-string-search " " str)(setq str (vl-string-subst "" " " str)))
str
)
(if clear_spaces (setq str (clear_empty_spaces str)))
(setq poz 0)
(while (and str (> (strlen str) 0) (numberp poz))
(setq poz (vl-string-position (ascii delimiter) str))
(if (and str (> (strlen str) 0))
(cond ((and (numberp poz)(>= poz 0))(setq ret (cons (substr str 1 poz) ret) str (substr str (+ poz 2))))
(T (setq ret (cons str ret) str nil))
)
)
)
(mapcar '(lambda (x) (if (numberp (read x)) (setq x (read x)) x))(reverse ret))
)
(princ "\nFunction READ_TO_LST converts delimited string into a list.")
(princ "\nUsage example: (read_to_list str \",\" nil) or any applicable string delimiter.")
(princ)
Command: (setq str "1000,1947958.861,1165020.235,588.929,B BOC")
"1000,1947958.861,1165020.235,588.929,B BOC"
Command: (read_to_lst str "," nil)
(1000 1.94796e+006 1.16502e+006 588.929 "B BOC")
Miljenko Hatlak

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.