// Remember that the character "0" has the ASCII value 48
// so if we subtract 48 from every ASCII value we got
// and find a value between 0 and 9, means we got our number ;)
char s[] = "abc123def456g7h8i90";
for (int i = 0; i = 0 && diff < 10) {
return true;
}
}
Anonymous
Sep 5, 2014
C++ solution:
bool containsNumber(string s)
{
if (s.find_first_of("0123456789") != string::npos)
{
return true;
}
return false;
}
Anonymous
Oct 10, 2014
//Check if a String contains a number or not
function find_digit(str) {
var search_result = str.search(/[0-9]/g);
if (search_result < 0) {
// or return false
return console.log("nothing");
} else {
// or return true
return console.log(str[search_result]);
}
}