Skip to content

Instantly share code, notes, and snippets.

@sathishvj
Created August 15, 2015 09:58
Show Gist options
  • Save sathishvj/ab5540f0316ffd4e65bc to your computer and use it in GitHub Desktop.
Save sathishvj/ab5540f0316ffd4e65bc to your computer and use it in GitHub Desktop.
Count Digits in a String
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