Golang determines whether a character is a letter

Release: 2019-12-31 16:27:22
Original
8940 people have browsed it

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
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template