feargt Posted May 28, 2013 Posted May 28, 2013 Hi, I have a string that I obtain from excel (0.0 1.2 1.2 1.2), I can convert that to a list so that it is ("0.0" "1.2" "1.2" "1.2") how can I convert it that each string in the list is actually a real number? I thought I could use the "foreach" function combined with atof but I cannot seem to get it to work. any ideas? thanks Quote
Tharwat Posted May 28, 2013 Posted May 28, 2013 If you wish to use foreach function , here is an example . (foreach x '("0.0" "1.2" "1.2" "1.2") (setq l (cons (read x) l)) ) (reverse l) Quote
MSasu Posted May 28, 2013 Posted May 28, 2013 I have a string that I obtain from excel (0.0 1.2 1.2 1.2) Please don't miss that what you have listed there is a list, not a string. A string will look like: "0.0 1.2 1.2 1.2" And you will need to split it by spaces and after use ATOF or DISTOF to convert in real numbers. Quote
feargt Posted May 28, 2013 Author Posted May 28, 2013 Hi, That is giving me an error. see below code. (setq dist_list (getcell "I10")) (setq dist_list (sinc:String->List dist_list " ")) (foreach x dist_list (setq dist_list1 (cons (read x) dist_list)) ) (reverse dist_list1) (print dist_list1) (1.2 "0.0" "1.2" "1.2" "1.2") Fehlerhafter Argumenttyp: numberp: "0.0" Quote
Tharwat Posted May 28, 2013 Posted May 28, 2013 Maybe , check it out (setq dist_list1 (cons (read x) dist_list[color=red]1[/color])) Quote
feargt Posted May 28, 2013 Author Posted May 28, 2013 I have used this from another forum by pbejse! (mapcar 'Read dist_list) Quote
Tharwat Posted May 28, 2013 Posted May 28, 2013 I have used this from another forum by pbejse! The majority of talent users have accounts in all around forums , so if you post your question all around the forums , you'd get and see the same users with the same answer mostly . Quote
Lee Mac Posted May 28, 2013 Posted May 28, 2013 (setq dist_list (getcell "I10")) (setq dist_list (sinc:String->List dist_list " ")) (foreach x dist_list (setq dist_list1 (cons (read x) dist_list)) ) (reverse dist_list1) (print dist_list1) You can skip a few steps: (read (strcat "(" (getcell "I10") ")")) Quote
pBe Posted May 28, 2013 Posted May 28, 2013 ..(setq dist_list (getcell "I10")) (setq dist_list (sinc:String->List dist_list " "))...... The OP and i never got that far on the other forum , I guess it depends on the getcell or sinc:String->List subfunction feargt is using. as you can see from the "error" (1.2 "0.0" "1.2" "1.2" "1.2") Fehlerhafter Argumenttyp: numberp: "0.0" Somewhere along the way, one of the element ended up as a real number. You can skip a few steps: (read (strcat "(" (getcell "I10") ")")) Then yes, Lee's suggestion to skip conversion of cell value to string and then back makes sense. Quote
feargt Posted May 29, 2013 Author Posted May 29, 2013 (read (strcat "(" (getcell "I10") ")")) the above was actually originally posted by Lee-MAc Thanks for all the replies on this. I will try this one out later today. 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.