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
Get Hours, Days, Minutes and Seconds difference between two dates [Future and Past]
How to set timeout for http.Get() requests in Golang?
How to check if a string contains a numbers in Golang?
Sample program to create csv and write data
Example to handle GET and POST request in Golang
How to read input from console line?
Golang Functions Returning Multiple Values
Golang Slice interface and array concatenation
How pointer & and * and ** works in Golang?
How to reads and decodes JSON values from an input stream?