M
Mike Copeland
Is there a relatively easy and simple way to determine if a
basic::string value is comprised only of numeric digits? I have an
application that parses a comma-delimited string, and I want to test if
specific values are strictly numeric. It was working until I got a
mixed alphanumeric value that started with a numeric digit (e.g.
"6btt123"), which caused the following code to fail:
int ii = atoi(wStr.c_str());
if(ii) // numeric processing
{
// expecting purely numeric value in "ii"
[etc.]
}
else // alphanumeric processing
{
// process alphanumeric data
}
when it fell into the numeric processing branch.
I know that I could examine the contents of the "wStr" string
character-by-character to test if each character is a digit character,
but that seems slow and inefficient. Is there a better way to do such
processing? Thoughts? TIA
basic::string value is comprised only of numeric digits? I have an
application that parses a comma-delimited string, and I want to test if
specific values are strictly numeric. It was working until I got a
mixed alphanumeric value that started with a numeric digit (e.g.
"6btt123"), which caused the following code to fail:
int ii = atoi(wStr.c_str());
if(ii) // numeric processing
{
// expecting purely numeric value in "ii"
[etc.]
}
else // alphanumeric processing
{
// process alphanumeric data
}
when it fell into the numeric processing branch.
I know that I could examine the contents of the "wStr" string
character-by-character to test if each character is a digit character,
but that seems slow and inefficient. Is there a better way to do such
processing? Thoughts? TIA