Author Topic: Tip (removing spaces from numbers)  (Read 3070 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Tip (removing spaces from numbers)
« on: August 09, 2004, 02:12:28 PM »
Most of you probably know this but............

remove all spaces from around a number and return just the number
Code: [Select]
(rtos (atof "  34.988     ") 2 3)
--> "34.988"


same thing for integers
Code: [Select]
(itoa (atoi "  34     "))
--> "34"
TheSwamp.org  (serving the CAD community since 2003)

Ron Heigh

  • Guest
Tip (removing spaces from numbers)
« Reply #1 on: August 09, 2004, 03:14:55 PM »
Nice tip Mark.

rude dog

  • Guest
Tip (removing spaces from numbers)
« Reply #2 on: August 10, 2004, 04:31:14 AM »
hey...kinda cool..didnt know that :)

CADaver

  • Guest
Tip (removing spaces from numbers)
« Reply #3 on: August 10, 2004, 07:20:31 AM »
Well, I'll be danged, I ain't gonna tell ya' how I have been doing it.

daron

  • Guest
Tip (removing spaces from numbers)
« Reply #4 on: August 10, 2004, 07:52:58 AM »
The other way could be to use find with a space and replace it with nothing, but Mark's way is much safer, until you can't convert it into a number like: "    34a   ".

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Tip (removing spaces from numbers)
« Reply #5 on: August 10, 2004, 09:39:53 AM »
The other way is to use VL ..
Code: [Select]

 (VL-STRING-TRIM " " "    34.988     " )
 (VL-STRING-TRIM " " "  34           " )
The poor cat gets skinned yet again ..
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.

SPDCad

  • Bull Frog
  • Posts: 453
Tip (removing spaces from numbers)
« Reply #6 on: August 10, 2004, 11:44:54 AM »
Nice Tip Mark!

To think I wrote a lisp that would eliminate spaces and convert a string number to a real number.  Its a good thing my lisp works with other string characters besides spaces or else I would feel real bad.
AutoCAD 2010, w/ OpenDCL

visit: http://reachme.at/spd_designs