LinkedIn interview question

Check if a String contains a number or not

Interview Answers

Anonymous

29 Jul 2014

String s= "abcabddd1"; char[] ch=s.toCharArray(); for(char c:ch){ if(Character.isDigit(c)){ break; } }

2

Anonymous

25 Jul 2014

ATOI conversion .

3

Anonymous

19 Aug 2014

// 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

5 Sept 2014

C++ solution: bool containsNumber(string s) { if (s.find_first_of("0123456789") != string::npos) { return true; } return false; }

Anonymous

10 Oct 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]); } }