Given a rune value, check if the rune is a Chinese character.
Run Code on Go Playground
package main
import (
"fmt"
"unicode"
)
func main() {
str := "hello, 世界"
for _, runeValue := range str {
if unicode.Is(unicode.Han, runeValue) {
fmt.Println(string(runeValue), "is a Chinese character")
} else {
fmt.Println(string(runeValue), "is not a Chinese character")
}
}
}
Output
h is not a Chinese character
e is not a Chinese character
l is not a Chinese character
l is not a Chinese character
o is not a Chinese character
, is not a Chinese character
is not a Chinese character
世 is a Chinese character
界 is a Chinese character
Tested on: Go Playground
References: