Extract integers from a string
Hello,
I'm trying to write a program that would prints out any numbers contained in a string along with the number of numbers found.
I have no clue on how to do it, could someone help me with this?
Thanks in advance
I'm trying to write a program that would prints out any numbers contained in a string along with the number of numbers found.
I have no clue on how to do it, could someone help me with this?
Thanks in advance
0
Comments
Best idea I can think of is to make a loop and compare each object in the string and check to see if the object was 0-9. If it is 0-9 it would up a counter which would take care of your number of numbers. Within the loop you could print the character.
I would like to process any string like "I have 22 trousers" and the procedure shoulkd return "22" and "2" because there are 2 numbers
Here is some explanations about what I have to do:
i mean its easy enough, when you find a character representing a number check to see if the next character also represents a number and if it does multiply the first digit by 10 and add the current one, then add to some array you're building
and your strings are either null terminated or you're given a length (otherwise you wouldn't know how big the string is) so you have a definitive end