Hi all, I would like to know how to check if the first two characters in a string are equal to a value.e.g I have a string containing 701285463257.
if(first two characters are 70){int o=2;}
else{o=3;}
Thanks :D
I would add a guard using 2 <= someString.length(), as operator[] doesn't like being used on empty strings.
Last edited on
Alternatively, someString.substr(2)=="70"
, although it's a little more expensive.
Another approach I sometimes use is 0 == someString.find("70")