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
Split a string at uppercase letters using regular expression in Golang
Simple function with return value in Golang
Regular expression to extract text between square brackets
How to find length of Map in Go?
How to get current IP form ipify.org ?
Regular Expression to get a string between parentheses in Golang