Author Topic: Extract integer from string  (Read 2143 times)

0 Members and 1 Guest are viewing this topic.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Extract integer from string
« on: September 29, 2008, 01:11:04 PM »
I'm in a bit of a bind here... I need to be able to extract a number from a string.  Here's the catch: If the number is 12.7, I just need to extract the numbers to the left of the decimal, I.E. 12.  I know this is one of those stupid-simple problems, but I can't seem to figure it out.  I know I'm over-analyzing this - been looking at this code for too long.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Extract integer from string
« Reply #1 on: September 29, 2008, 01:15:46 PM »
well, I would start by reading each character from left to right and checking it against the ascii of 0-9.  Once you get your first "number" set a bool to true, then while next character is 0-9, cont, stop when false thus eliminating the " . "  And while true, keep concatinating the next numb to the prev set
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Spike Wilbury

  • Guest
Re: Extract integer from string
« Reply #2 on: September 29, 2008, 01:18:06 PM »
I do not know much about the dark side coding... but have a look here:

http://www.avdf.com/apr98/art_vb003.html


HTH, maybe....

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Extract integer from string
« Reply #3 on: September 29, 2008, 01:22:59 PM »
Hey Luis, good find
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)