How to check string contains uppercase lowercase character in Golang?
Checking if any character of given string is Uppercase or Lowercase. The Unicode package's IsLower() and IsUpper() function is used to check each character of given string.
Check any character is uppercase or lowercase
package main
import (
"fmt"
"unicode"
)
func main() {
word := "Hello World"
hasUpper := false
hasLower := false
for _, r := range word {
if unicode.IsUpper(r) {
hasUpper = true
}
if unicode.IsLower(r) {
hasLower = true
}
}
fmt.Println(hasUpper)
fmt.Println(hasLower)
}
Most Helpful This Week
How to check lowercase characters in a string in Golang?
How to remove multiple spaces in a string in GoLang?
How to remove special characters from a string in GoLang?
How to trim leading and trailing white spaces of a string in Golang?
How to check if a string contains a substring in Golang?
How to check if a string contains a white space in Golang?