how to convert text readed from barcode to arabic text

孤街浪徒 提交于 2019-12-24 00:56:34

问题


I have barcode image with type "pdf417",it content a arabic text , When read it using barcode it through a text like this "ÃÍãÏ#" how can I convert this text to its original text (arabic)


回答1:


If your method gives you a byte[] use:

var str = Encoding.UTF8.GetString(yourBytes);

or, perhaps

var str = Encoding.GetEncoding(1256) // 1256 is the Windows Arabic codepage
                  .GetString(yourBytes);

If your method gives you a string do this:

// iso-8859-1 is a codepage that can be used to convert back some 
// malformed unicode strings
var str = Encoding.GetEncoding(1256)
                  .GetString(Encoding.GetEncoding("iso-8859-1")
                                     .GetBytes(yourString));

The text you had in your question in the beginning was converted with this to:

أحمد#المنير#محمد#فاطمه #حرستا 27-12-1949#

Note that only the UTF8 format will make the barcode "universal" (because UTF8 can represent all the Unicode characters). The 1256 codepage will make your barcode "regional" (you have to know where your barcode was written to imagine it could be encoded with the 1256 Windows Arabic codepage)



来源:https://stackoverflow.com/questions/18170590/how-to-convert-text-readed-from-barcode-to-arabic-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!