Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*jeffstamper
Message 1 of 6 (176 Views)

Converting string to integer

176 Views, 5 Replies
02-19-2000 08:18 AM
I am writing a LISP routine where I need to convert string data into an
integer. Unfortuanately I only know the commands for converting integers
and real numbers into string. Does anyone have any suggestions. Thanks.

Jeff Stamper
Orlando
*Kenewell, Phil
Message 2 of 6 (176 Views)

Re: Converting string to integer

02-19-2000 08:38 AM in reply to: *jeffstamper
Jeff,

Here you are:

-------------------------------
Given: INT, REAL, or ANG

1.) Integer to String:
(itoa INT)

2.) Real to String:
(rtos REAL [Units mode][Precision]) The extra paramters are optional.

3.) Angle (in radians) to String:
(angtos ANG [Units Mode])

Examples:

(setq a 1)
(itoa a)
"1"

(setq a 1.25)
(rtos a 2 4)
"1.2500"

(setq a pi)
(angtos a 0)
"180.0"

----------------------------------
Given STR

1.) String to Integer:
(atoi STR)

2.) String to Real (decimal only)
(atof STR)

3.) Formatted String to Real:
(distof STR)

Examples:

(setq a "1")
(atoi a)
1

(setq a "1.25")
(atof a)
1.25

(setq a "1 1/2")
(distof a)
1.5

----------------------------------

--
Phillip Kenewell
CAD Systems Technician
Air Gage Company
pkenewell@airgage.com
===================
> Not < a Member of the AutoDESK
Discussion Forum Moderator Program

jeffstamper wrote in message
news:88mfs7$fi62@adesknews2.autodesk.com...
> I am writing a LISP routine where I need to convert string data into an
> integer. Unfortuanately I only know the commands for converting integers
> and real numbers into string. Does anyone have any suggestions. Thanks.
*Wheat, Chuck
Message 3 of 6 (176 Views)

Re: Converting string to integer

02-19-2000 09:08 AM in reply to: *jeffstamper
You might also take a look at the read function. It is also capable of
receiving a string and returning an integer. But I'm not clear on when one
would choose this over atoi and I would tend to use atoi. I only mention
this for the sake of completeness .

--
~ ~ ~ ~ ~ ~ ~ ~
Chuck Wheat
cwheat233@yahoo.com
Denver, Colorado, USA
~ ~ ~ ~ ~ ~ ~ ~
*Nunez, Gaston
Message 4 of 6 (176 Views)

Re: Converting string to integer

02-19-2000 10:03 AM in reply to: *jeffstamper
Jeff:

(atoi "string")

-gnb

jeffstamper wrote:

> I am writing a LISP routine where I need to convert string data into an
> integer. Unfortuanately I only know the commands for converting integers
> and real numbers into string. Does anyone have any suggestions. Thanks.
>
> Jeff Stamper
> Orlando
*toddh
Message 5 of 6 (176 Views)

Re:

02-23-2000 07:57 AM in reply to: *jeffstamper
x-no-archive: yes
>You might also take a look at the read function. It is also capable of
>receiving a string and returning an integer. But I'm not clear on when one
>would choose this over atoi and I would tend to use atoi. I only mention
>this for the sake of completeness .
Never use the (read) function for converting a string to an integer
(or real). It was not intended for this purpose really, but mainly to
convert a string to a symbol or list.

(read "ABC") > ABC type='SYM
(atoi "ABC") > 0 type='INT

(read "12A") > 12A type='SYM
(atoi "12A") > 12 type='INT

(read "12") > 12 type='INT
(atoi "12") > 12 type='INT

(read "(12)") > (12) type='LIST
(atoi "(12)") > 0 type='INT

As you can see, the return type from (read) can vary. With (atoi), you
will always get an integer type returned. But there are more serious
problems to be had with (read).

(read "(12") > error: malformed list *Cancel*
Poof - your AutoLISP program just crashed. Only use (read) when you
are sure that a valid readable string is being passed. This function
is quite useful in incrementing symbols, reading expressions from
files, and building point lists. But there are better suited functions
to convert strings to numbers.

ToddH
Copyright(c) 1999
*Bell, R. Robert
Message 6 of 6 (176 Views)

Re:

02-23-2000 09:59 AM in reply to: *jeffstamper
Hey Todd, since it's 2000, and your copyrighted post (!) is dated 1999, does
that mean it's not a true copyright? How can you copyright such an
instructional post? Why?

--
R. Robert Bell, MCSE
Network Administrator (or, Modern-day Wizard)
(remove the "not." in my address for direct e-mail)
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.