Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a character is Russian

I would like to know if a string contains 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

What is the corresponding way to do it for Russian/Cyrillic alphabet?

like image 806
Thomas Avatar asked Jun 27 '17 20:06

Thomas


People also ask

What does a Russian C look like?

Russian letters that are (almost) the same.К к - Pronounced like the "k" in "kitten" or "kangaroo". This letter replaces the english "c" sound in words like "cat".

What does Z look like in Russian?

Ze (З з; italics: З з) is a letter of the Cyrillic script. It commonly represents the voiced alveolar fricative /z/, like the pronunciation of ⟨z⟩ in "zebra". Ze is romanized using the Latin letter ⟨z⟩.


2 Answers

This seems to work

unicode.Is(unicode.Cyrillic, r) // r is a rune
like image 170
Thomas Avatar answered Sep 22 '22 20:09

Thomas


I went on and did this example implementation for finding russian uppercase chars, 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 do any set of characters this way. Just modify the codes of characters you are interested in.

like image 20
K. Kirsz Avatar answered Sep 26 '22 20:09

K. Kirsz