|
|
|
#1 (permalink) | ||||||||||||||
|
Photography nut
![]() |
I'm looking for suggestions on the best way to find a number in a string, pull it out and convert it into an integer.
I know that the string class has a lot of available methods, but none seem to be what I need. I thought about using the getChar method, making the string into an array of characters and then searching for integer in it, but that seems to be a very sloppy and slow process. Is there another way I can go about this? Thanks for any help.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
|
|
#2 (permalink) | ||||||||||||||
|
Photography nut
![]() |
Well I came up with a way of doing it that turned out to not be nearly as bad as I thought it would.
I setup a for loop to look at the character at each index if it was a number I saved it to a new string then after the for-loop was done I parsed the string to an Integer.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
Apple Doesn't Love You
|
**EDIT**
nm - that was kinda useless - rewriting Code:
for(int i = 0; i < string.lenth; i++)
if(string.charAt(i) - '0' < 10)
int whatever = Integer.valueOf(string.charAt(i));
Last edited by rabidgnome229 : 03-04-07 at 09:00 PM. |
|||||||||||||
|
|
|
|
#4 (permalink) | ||||||||||||||
|
Photography nut
![]() |
hey, awesome.
Thats a bit cleaner than my design. Thanks!
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
|
|
#5 (permalink) | |||||||||||||
|
Apple Doesn't Love You
|
np
![]() If you have any more questions just ask
|
|||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|