Skip to content

Instantly share code, notes, and snippets.

@rmsj
Created September 30, 2021 23:30
Show Gist options
  • Save rmsj/876701da85bbba2f4748746d2154c22e to your computer and use it in GitHub Desktop.
Save rmsj/876701da85bbba2f4748746d2154c22e to your computer and use it in GitHub Desktop.
[Go Upper or Lower Case] Determine is a string is in lower or upper case in golang #go
func IsUpper(s string) bool {
for _, r := range s {
if !unicode.IsUpper(r) && unicode.IsLetter(r) {
return false
}
}
return true
}
func IsLower(s string) bool {
for _, r := range s {
if !unicode.IsLower(r) && unicode.IsLetter(r) {
return false
}
}
return true
}
func isFirstCharUpperCase(word string) bool {
runes := []rune(word)
if !unicode.IsUpper(runes[0]) || !unicode.IsLetter(runes[0]) {
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment