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
Find out how many logical processors used by current process
How to create thumbnail of an image?
How to iterate over a Map using for loop in Go?
Example: Fields and FieldsFunc from BYTES Package
Get Hours, Days, Minutes and Seconds difference between two dates [Future and Past]
How to Convert string to integer type in Go?