Home >Backend Development >Golang >Golang determines whether a character is a letter

Golang determines whether a character is a letter

尚
Original
2019-12-31 16:27:228989browse

Golang determines whether a character is a letter

go languageYou can use the IsLetter method of the unicode package to determine whether a character is a letter.

func IsLetter(r rune) bool

IsLetter Reports whether the rune is a letter (category L).

// IsLetter 判断 r 是否为一个字母字符 (类别 L)
// 汉字也是一个字母字符
func IsLetter(r rune) bool
func main() {
s := "Hello\n\t世界!"
for _, r := range s {
fmt.Printf("%c = %v\n", r, unicode.IsLetter(r))
} // Hello世界 = true
}

For more golang knowledge, please pay attention to the golang tutorial column.

The above is the detailed content of Golang determines whether a character is a letter. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn