I got into another issue while trying to parse an integer.
This integer is received as part of a string eg: "num: 987"
where "num: " is fix and using substr() I get the "987"
The problem is I don't actually get only that, I also get "987kjshd"
A total of 8 characters (which my guess is the minimum array size for type string)
so I'm trying to figure how to ensure that I will be actually checking the "987" only. because the method I'm using it returns always false because there are extra characters in the string I'm evaluating.
int main()
{
std::string str = "789sjhgdf";
unsignedint index = 0;
while( index < str.length() )
{
// Check against the ascii decimal values and don't run past the length of the string.
if( ( str[ index ] > 47 ) && ( str[ index ] < 58 ) && ( index < str.length() ) )
{
std::cout << str[ index ] << " is a number.\n";
}
else
{
std::cout << str[ index ] << " was not a number.\n";
}
++index;
}
return 0;
}
7 is a number.
8 is a number.
9 is a number.
s was not a number.
j was not a number.
h was not a number.
g was not a number.
d was not a number.
f was not a number.
indeed LowestOne, it seems I was using the wrong length and that's why I was getting an string of fix length (8) rather than one of the exact length. Having said that I'm still trying to digest those null-end characters. I'm against the time right now, that's why I just used strings to manipulate char arrays, but I hope spend some time trying to understand that as well.