Created
August 15, 2015 09:58
-
-
Save sathishvj/ab5540f0316ffd4e65bc to your computer and use it in GitHub Desktop.
Count Digits in a String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func countDigitsIn(s string) int { | |
if len(s) == 0 { | |
return 0 | |
} | |
digitsCount := 0 | |
for _, v:=range s { | |
if v=='0' || v=='1' || v=='2' || v=='3' || v=='4' || v=='5' || v=='6' || v=='7' || v=='8' || v=='9' { | |
digitsCount++ | |
} | |
} | |
return digitsCount | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment