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?
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".
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⟩.
This seems to work
unicode.Is(unicode.Cyrillic, r) // r is a rune
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With