6

Possible Duplicate:
Return the language of a given string

The task is to sort the list of strings. With priority to a specific language. Strings can be written in different languages. Such as Chinese, English, Russian. And I need to first take all the Chinese, and then the rest.

To do this, I want to know what country (language) belongs to a particular character in a string. ( For example on the first letter of)

Are there any classes or methods?

Community
  • 1
  • 1
Mixer
  • 1,292
  • 3
  • 22
  • 41
  • 1
    Try this link. http://stackoverflow.com/questions/1192768/return-the-language-of-a-given-string/1192802#1192802 – D J Jan 25 '13 at 17:07
  • 1
    I voted to close based on D J's link because it sounds like two different problems. One is to identify the language, which is the link, and the other is to sort by what is identified, which is pretty simple. – Yuriy Faktorovich Jan 25 '13 at 17:09
  • [What have you tried?](http://whathaveyoutried.com/) – jalf Jan 25 '13 at 17:14
  • I thought about the method that suggested Baboon And the study of the class System.Text.UnicodeEncoding makes me think otherwise. Too many features to unicode, to do a simple cast. But it would be a nice solution use of library functions. – Mixer Jan 25 '13 at 17:32
  • Google API is poor solution, i need detect lang only C# code without network – nim Dec 08 '14 at 05:34

2 Answers2

5

If we're talking alphabets, then you can simply check the int representation of a char by casting it:

int unicodeValue = (int)myString[0];

Then using a table such as this one you check if it's within the limit of a language.
For example, is 19984, which is 4E10 in hexadecimal (19984.ToString("X")), making it a CJK Unified Ideographs. It looks like this it's the category for chinese characters, but you need to dig around and make sure.

Now if we're talking about determining which language is a particular word from, you need to look into Soundex algorithms.

Louis Kottmann
  • 16,268
  • 4
  • 64
  • 88
1

Try this link

How to detect the language of a string?

Code is(Copied)

var text = "¿Dónde está el baño?";
google.language.detect(text, function(result) {
if (!result.error) {
var language = 'unknown';
for (l in google.language.Languages) {
  if (google.language.Languages[l] == result.language) {
    language = l;
    break;
  }
}
var container = document.getElementById("detection");
container.innerHTML = text + " is: " + language + "";
}
});
Community
  • 1
  • 1
D J
  • 6,908
  • 13
  • 43
  • 75