I'm reading from a file and parsing its contents. I need to make sure a CString
value consist of only numbers. What are the different methods i could achieve it?
Sample code:
Cstring Validate(CString str)
{
if(/*condition to check whether its all numeric data in the string*/)
{
return " string only numeric characters";
}
else
{
return "string contains non numeric characters";
}
}
You can iterate over all characters and check with the function
isdigit
whether the character is numeric.Another solution that does not use
isdigit
but only CString member functions usesSpanIncluding
: