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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
AlanRank #669 · 3.6K reputationPosted Jun 25, 2007, 2:36 AM EDT
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.
Mike GoldRank #50 · 30.6K reputationPosted Jun 25, 2007, 7:20 PM EDT
abdrabaa11 reputationPosted Jun 25, 2007, 9:52 PM EDT
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
AlanRank #669 · 3.6K reputationPosted Jun 26, 2007, 2:06 AM EDT
For example "%!$*?" is gibberish in any language but the characters all have unicode values less than 128.