Answer the question
In order to leave comments, you need to log in
How to determine the language in a string?
Good afternoon. There is a string of 4-9 characters.
I need to understand what language this word is in. Either Russian or English.
Can you please tell me how to implement a string check for language belonging?
I have an idea, cut the string to one character, check this character with the ASCII code, and if the code matches the letter, then determine. But I got up on the problem of translating a string from one letter into a symbol. Only the ToCharArray() method is shown.
Can you please tell me how to implement this correctly? Thanks in advance .
Answer the question
In order to leave comments, you need to log in
You can get the first character with [0].
And you can just check:
if (myString[0] >= 'a' && 'z' <= myString[0])
Using regular expressions
if (!Regex.IsMatch(stringToCheck, @"\P{IsCyrillic}"))
{
// Сработает если все символы - кириллица
}
if (!Regex.IsMatch(stringToCheck, @"\p{IsCyrillic}"))
{
// Сработает если хотя бы один символ - кириллица
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question