Check if the character is Russian

I would like to know if the string contains in Russian / Cyrillic characters.

For latin characters, I do something like this (pseudocode):

text := "test"
for _, r := range []rune(text) {
    if r >= 'a' && r <= 'z' {
        return True
    }
}
return False

      

How can this be done for the Russian / Cyrillic alphabet?

+3


source to share


2 answers


It seems to work



unicode.Is(unicode.Cyrillic, r) // r is a rune

      

+9


source


I went ahead and followed this example to find uppercase Russian characters based on this Unicode chart :

func isRussianUpper(text string) bool {
    for _, r := range []rune(text) {
        if r < '\u0410' || r > '\u042F' {
            return false
        }
    }
    return true
}

      



You can make any character set this way. Just change the character codes that interest you.

+1


source







All Articles