string str = "3257fg"; for(int i = 0;i < (strlen(str) - 1);i++) { if((int)str[i] < 10) { // it is a number, so do some code } else { // it is not a number, do something else } }