Convert string to list - coordinates

21 views
Skip to first unread message

Jer

unread,
Jan 25, 2011, 11:00:38 AM1/25/11
to Customize your ACAD
In converting a string to a list I come across a loss on coordinate
precision:

(read (strcat "(" "123456789.123 123456789.123 123456789.123" ")"))

returns:

(1.23457e+008 1.23457e+008 1.23457e+008)

...not only losing the decimal places but a few steps in front of
it... I've used this method before but it must have been with smaller
numbers...

Is there a way I can change that string into a list w/o losing
precision?

I hate to make a 2x question post but It might save me a step
entirely; is there a easy way to just replace the spaces for commas in
that string?

"123456789.123 123456789.123 123456789.123"
to
"123456789.123,123456789.123,123456789.123"

??

Thanks for the help!
Jer

Masani

unread,
Jan 26, 2011, 11:35:05 PM1/26/11
to Customize your ACAD

;|
To my understating you are expecting a list from a string which is
delaminated with spaces.
or a string which should have a comma instead of commas
|;

;; Let us take the same string that you have with spaces
(setq myString "123456789.123 123456789.123 123456789.123")
;;we can use the cl-string-subst function to replace a character with
other
;;look at the following example
(setq rtnString(VL-STRING-SUBST "," " " myString))
;;this should return : "123456789.123,123456789.123 123456789.123"

;;In you case when we use the read function
(setq myList (read (strcat "(" mystring ")")))
;;this should return : (1.23457e+008 1.23457e+008 1.23457e+008)

;;Even it is displaying e+008 something that will store the exact
value in it
;; we can use this variable where ever it is required. Let me take the
first value and convert back into string
(setq firstString(rtos (car myList) 2 16))
;;It will return : "123456789.1230000"
;; this is the same value we have supplied to read function.

;; I think this will answer your question. Please let me know if you
have any other questions on this.

Andrew Lawrence Merryman

unread,
Jan 26, 2011, 11:52:19 PM1/26/11
to customize...@googlegroups.com
jer, 

masani's correct in that autocad is displaying the value differently, when in actual fact the value is no different from what you're inputting.

though, i have to ask: if you are expecting to create a list, are you aware of the (list) and (vl-string->list) functions?

i believe they may offer a more direct solution.

good luck, 

drew

 

Senthil Prabu

unread,
Jan 29, 2011, 6:01:21 PM1/29/11
to customize...@googlegroups.com
Excellent sir

> --
> You received this message because you are subscribed to the Google Groups
> "Customize your ACAD" group.
> To post to this group, send email to customize...@googlegroups.com.
> To unsubscribe from this group, send email to
> customize-your-...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/customize-your-acad?hl=en.
>
>

--
Sent from my mobile device

Reply all
Reply to author
Forward
0 new messages