Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check whether unicode text is in a certain language?

Tags:

I'll be getting text from a user that I need to validate is a Chinese character.

Is there any way I can check this?

like image 376
Diskdrive Avatar asked May 22 '11 13:05

Diskdrive


1 Answers

You can use regular expression to match with Supported Named Blocks:

private static readonly Regex cjkCharRegex = new Regex(@"\p{IsCJKUnifiedIdeographs}"); public static bool IsChinese(this char c) {     return cjkCharRegex.IsMatch(c.ToString()); } 

Then, you can use:

if (sometext.Any(z=>z.IsChinese()))      DoSomething(); 
like image 174
Tyler Liu Avatar answered Sep 24 '22 02:09

Tyler Liu