Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find a Unicode character's bidirectional character type in C#?

Is there any way I can find a Unicode character's bidirectional character type in C#?

I want to look through the characters in a string and decide if they are all strong LTR, strong RTL, a mixture of strong LTR and neutral, etc.

like image 355
Bernard Darnton Avatar asked Aug 31 '11 09:08

Bernard Darnton


People also ask

What is a bidirectional character?

Bidirectional (BIDI) text results when texts of different direction orientation appear together. For example, English text is read from left to right. Arabic and Hebrew texts are read from right to left. If both English and Hebrew texts appear on the same line, the text is bidirectional.

What is Unicode Bidirectional algorithm?

The Unicode Bidirectional Algorithm is designed so that the use of explicit formatting characters can be equivalently represented by out-of-line information, such as stylesheet information or markup. Conflicts can arise if markup and explicitly formatting characters are both used in the same paragraph.

Can C handle Unicode?

It can represent all 1,114,112 Unicode characters. Most C code that deals with strings on a byte-by-byte basis still works, since UTF-8 is fully compatible with 7-bit ASCII.


1 Answers

System.Globalization.CharUnicodeInfo.GetBidiCategory(ch) is your friend.

The problem is that the function is internal. This MichKap (RIP) blog post shows you how to call it using reflection.

like image 199
Serge Wautier Avatar answered Oct 10 '22 23:10

Serge Wautier