Hi,
Is there a way to determine if a string contains Latin letters or not?
Or if the string is written in English or not?
Hi,
Is there a way to determine if a string contains Latin letters or not?
Or if the string is written in English or not?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Jun 26, 2007, 6:06 AM
For example "%!$*?" is gibberish in any language but the characters all have unicode values less than 128.
abdrabaaPosted Jun 26, 2007, 1:52 AM
i found the solution. the solution is by converting each letter to int32 to get the unicode by using System.Convert.ToInt32('anyletter'). letters from a to z should give number equal or less then 128.
thanks for help
Mike GoldPosted Jun 25, 2007, 11:20 PM
AlanPosted Jun 25, 2007, 6:36 AM
using System.Text.RegularExpressions;
........
string s = "abcABC"; // or whatever
Regex r = new Regex("[a-zA-z]+");
bool containsLatinLetters = r.IsMatch(s);
It's not difficult to extend this technique to check that a string contains no other characters apart from Latin letters, numerals and punctuation used in the English language.
However, having done that, it would still be difficult to check that the string was actually written in English. A possible technique would be to parse the string into individual words and check whether they all occurred in an English dictionary or not.