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 fix race condition using Atomic Functions in Golang?
Golang Slice interface and array concatenation
Regular expression to extract DNS host-name or IP Address from string
Example: ReadAll, ReadDir, and ReadFile from IO Package
Convert specific UTC date time to PST, HST, MST and SGT
Encoding and Decoding using json.Marshal and json.Unmarshal