Computer Science Canada Need help with string manipulation |
Author: | yingmu [ Sun Apr 10, 2005 7:59 pm ] |
Post subject: | Need help with string manipulation |
ok u have a string, and the beginning part was a number followed by words with no space in between, how do u get the number into interger, ex. if the string was "123abc" how do u get the number 123? plz help, thx [/b] |
Author: | jamonathin [ Sun Apr 10, 2005 8:08 pm ] | ||
Post subject: | |||
This is what I got, but there's some errors, or attributes, depends on how you see it. It'll take the number out, but it will put the number in order.
use "1231abc" and see for yourself. I can't think of anything else right now, but i figured this was better than nothing. |
Author: | jamonathin [ Sun Apr 10, 2005 8:21 pm ] | ||
Post subject: | |||
Here yas go. I did it backwards, here's the final good copy.
What you do is check every character in the string to see if there's a number, if there is, add it to a variable that can hold the information, then transfer the information to an integer variable. |
Author: | McKenzie [ Sun Apr 10, 2005 8:30 pm ] |
Post subject: | |
yingmu, Unless you are trying to go above and beyond I've said that you only need to worry about one digit numbers. |
Author: | jamonathin [ Sun Apr 10, 2005 8:34 pm ] |
Post subject: | |
McKenzie wrote: yingmu,
Unless you are trying to go above and beyond I've said that you only need to worry about one digit numbers. why should he only stick to 1-digit? |