Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect input string characters language with build in .NET functionalities?

Tags:

c#

.net

vb.net

I want to detect if my input string has Arabic characters in it.
Maybe some code like this :

string str = "سS";
str[0].IsArabicCharacter(); //true
str[1].IsArabicCharacter(); //false

Currently using mapping but I want to migrate to some C# built in feature.

ArabicChars = "ساینبتسیکبدثصکبثحصخبدوزطئظضچج";
string str = "ل";
if(ArabicChars.Contains(str[0]) return true; else return false;
like image 847
Mohsen Sarkar Avatar asked Apr 10 '13 06:04

Mohsen Sarkar


1 Answers

The best you're going to get is going to be the various RegEx unicode block character class: \p{name}

Regex.IsMatch(str[0], @"\p{IsThai}");
Regex.IsMatch(str[1], @"\p{IsArabic}");

MSDN Reference Pages:

  • Unicode Category or Unicode Block
  • List of supported named Unicode Blocks
like image 141
Eric Falsken Avatar answered Nov 05 '22 10:11

Eric Falsken