如何将 unicode 编码数据转换为 Devanagri(印地语) 文本
我正在将 Devanagri(印地语)脚本中的 SMS 消息从手机接收到桌面程序中,但它以编码(例如 - 091A09470924002009240924)显示数据,我发现这是 unicode。是否有现有的库可以让我将其转换为印地文文本?如果没有,我该如何为此编写一个方法?我正在使用 C#。
I am receiving SMS messages in the Devanagri (Hindi) script from my mobile phone into my desktop program, but it is displaying the data in an encoding (Eg. - 091A09470924002009240924) which I found out is unicode. Is there an existing library that will allow me to convert this to hindi text? If not, how do I go about writing a method for this? I'm using C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 System.Text.Encoding 类。它有方法 GetChars(byte[])。您可能需要合适的字体,因为某些印地语符号可以通过多种方式书写。
Use System.Text.Encoding class. It has method GetChars(byte[]). And probably you'll need an appropriate font since some Hindi symbols can be written in several ways.
以下是我用于将 格鲁吉亚语 unicode 转换为其拉丁语等效文本的代码片段。
仅解释必要的部分:
Encoding.Unicode.GetBytes(unicodeString);
返回字节数组,该数组的长度为2 * unicodeString.Length
。这样 unicodestring 中的每个字母都有一对字节。为了更好的解释这里附有图像
unicodeBytes
甚至索引也有代表字母的值你想要解码。格鲁吉亚字母表的第一个字母从 208 开始,到 240 结束(总共 33 个)。因此,如果unicodeBytes
值在 [208;240] 范围内,我必须使用charset
字符串数组来获取等效的拉丁文,否则unicodeBytes
值只是字符代码。我不知道是否有一个库,但此方法将为您提供如何编写自己的转换器的基本概念。
Here's code snippet I used for converting Georgian unicode to its Latin equivalent text.
explaining only the necessary part:
Encoding.Unicode.GetBytes(unicodeString);
returns array of bytes, length of this array is2 * unicodeString.Length
. so that every letter from unicodestring has a pair of bytes.for a better explanation heres image attached
unicodeBytes
even indexes have values representing the letter you want to decode. first letter of the Georgian alphabet was starting at 208 ending at 240 (33 in total). so ifunicodeBytes
value was in the range of [208;240] i had to use thecharset
string array to get the Latin equivalent, otherwiseunicodeBytes
value was just char code.I don't know if there is a library for it but this method will give you basic idea how to write your own convertor.
感谢您的回复,他们帮助我找到了确切的解决方案 - http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/12a3558d-fe48-44fd-840e-03facfd9c944
Thanks for the responses, they helped me find the exact solution - http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/12a3558d-fe48-44fd-840e-03facfd9c944