c# - How to detect whether a character belongs to a Right To Left language? -


what way tell whether string contains text in right left language.

i have found question suggests following approach:

public bool isarabic(string strcompare) {   char[] chars = strcompare.tochararray();   foreach (char ch in chars)     if (ch >= '\u0627' && ch <= '\u0649') return true;   return false; } 

while may work arabic doesn't seem cover other rtl languages such hebrew. there generic way know particular character belongs rtl language?

unicode characters have different properties associated them. these properties cannot derived code point; need table tells if character has property or not.

you interested in characters bidirectional property "r" or "al" (randalcat).

a randalcat character character unambiguously right-to-left directionality.

here's complete list of unicode 3.2 (from rfc 3454):

 d. bidirectional tables  d.1 characters bidirectional property "r" or "al"  ----- start table d.1 ----- 05be 05c0 05c3 05d0-05ea 05f0-05f4 061b 061f 0621-063a 0640-064a 066d-066f 0671-06d5 06dd 06e5-06e6 06fa-06fe 0700-070d 0710 0712-072c 0780-07a5 07b1 200f fb1d fb1f-fb28 fb2a-fb36 fb38-fb3c fb3e fb40-fb41 fb43-fb44 fb46-fbb1 fbd3-fd3d fd50-fd8f fd92-fdc7 fdf0-fdfc fe70-fe74 fe76-fefc ----- end table d.1 ----- 

here's code complete list of unicode 6.0:

var url = "http://www.unicode.org/public/6.0.0/ucd/unicodedata.txt";  var query = record in new webclient().downloadstring(url).split('\n')             !string.isnullorempty(record)             let properties = record.split(';')             properties[4] == "r" || properties[4] == "al"             select int.parse(properties[0], numberstyles.allowhexspecifier);  foreach (var codepoint in query) {     console.writeline(codepoint.tostring("x4")); } 

note these values unicode code points. strings in c#/.net utf-16 encoded , need converted unicode code points first (see char.converttoutf32). here's method checks if string contains @ least 1 randalcat character:

static void isanycharacterrighttoleft(string s) {     (var = 0; < s.length; += char.issurrogatepair(s, i) ? 2 : 1)     {         var codepoint = char.converttoutf32(s, i);         if (israndalcat(codepoint))         {             return true;         }     }     return false; } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -