I'm trying to search a string for numbers, to ensure that it only contains numbers and no characters - what's the easiest way to do this?
I thought it might be something likkkeee...
size_t x;
string y;
x = y.find('0-9');
if (x!=npos::strin g)
{
// if it contains anything but 0-9, exec code
}
else
{
// yeah
}
but, it doesn't seem to be working at all, yeeeah I'm sure that's a foolish way I just c an't think of any other way =(
Alright, new idea.. What if I convert it to a c string, and then convert it back later? that should get rid of any alphanumeric characters...
I thought it might be something likkkeee...
size_t x;
string y;
x = y.find('0-9');
if (x!=npos::strin g)
{
// if it contains anything but 0-9, exec code
}
else
{
// yeah
}
but, it doesn't seem to be working at all, yeeeah I'm sure that's a foolish way I just c an't think of any other way =(
Alright, new idea.. What if I convert it to a c string, and then convert it back later? that should get rid of any alphanumeric characters...
Comment