Author Topic: How do you derturman what type to convert to?  (Read 1681 times)

0 Members and 1 Guest are viewing this topic.

BazzaCAD

  • Guest
How do you derturman what type to convert to?
« on: June 22, 2007, 07:43:35 PM »
OK, so I'm reading in a .txt file, and of course everything comes in as a string.
Let's say I have ("abc" "123" "1.5")...
How do I leave the "abc" as a string, convert the "123" to an Int, & convert the "1.5" to a Float?

thx,
Barry

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How do you derturman what type to convert to?
« Reply #1 on: June 22, 2007, 07:58:16 PM »
Hi Barry.
perhaps something like ..
Code: [Select]
(setq
    varlist (list "abc" "123" "1.5")
    newlist '()
    )
(FOREACH var varlist
    (SETQ newlist (CONS (IF (DISTOF var)
                            (READ var)
                            var
                        )
                        newlist
                  )
    )
)
(setq newlist (reverse newlist))
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do you derturman what type to convert to?
« Reply #2 on: June 22, 2007, 08:00:04 PM »
Looking for another thread but found this one.
http://www.theswamp.org/index.php?topic=9780.msg125334#msg125334
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

BazzaCAD

  • Guest
Re: How do you derturman what type to convert to?
« Reply #4 on: June 22, 2007, 08:07:08 PM »
thx guys, works great...