如何将 UTF-8 阿拉伯字母转换为 CodePage 1001?
我有一个支持 CodePage 1001 阿拉伯语的 Star Micronics TSP,如何使用 C# 将 UTF-8 转换为该特定代码页?
更新:我发现 CodePage 864 与打印机兼容,我尝试发送十六进制值并且得到了正确的字符,
myPrinter.PrintNormal(PrinterStation.Receipt, "\xFE8D");
我尝试了以下将字符串转换为 codePage 864:
Encoding enc = Encoding.GetEncoding(864);
byte[] arr = enc.GetBytes("السلام");
编码后得到的字节 arr 值是{63,63,63,63,63,63}
的值是错误的,甚至字节计数也是错误的,因为它是双字节字符。
I have a Star Micronics TSP that supports CodePage 1001 Arabic, how do I convert UTF-8 to that specific code page using C#?
Update: I found out that CodePage 864 is compatible with the printer, I tried sending hex values and I got the correct character,
myPrinter.PrintNormal(PrinterStation.Receipt, "\xFE8D");
I tried the following to convert a string to codePage 864:
Encoding enc = Encoding.GetEncoding(864);
byte[] arr = enc.GetBytes("السلام");
the byte arr values i'm getting after the encoding is {63,63,63,63,63,63}
which is wrong in value and even the byte count is wrong because its a double byte character.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
未经测试,但是:
当然,如果您实际上以字符串开头,请跳过第一行,但既然您提到了 UTF-8,我就假设是二进制的。
显然,对于大数据量,您可以使用
TextReader
/TextWriter
(每个都带有编码) - 但想法相同。Untested, but:
Of course, skip the first line if you are actually starting with a string, but since you mention UTF-8 I assumed binary.
Obviously for large data volumes you might use a
TextReader
/TextWriter
(each with encoding) instead - but same idea.我不认为最初提出问题的人仍然需要答案,但这个线程似乎非常有名,我不希望任何人浪费时间来找到我发现的困难方法..所以
这个答案主要依赖于提供的应用程序Star Micronics TSP 打印机的
要点:
- 参考“Interop.OposPOSPrinter_CCO.dll”
- 打印机对象应该是oposposprinter.printer类型,并且以稍微不同的方式初始化(与opos.net相比)
- 字符代码作为字符串发送,并且有一个变量告诉打印机对象使用这些十进制数字作为字符代码
带有简单阿拉伯字母转换器的示例 VB.net 项目可以在 https://bitbucket.org/loody/arabic-1001/overview
注意:我没有时间覆盖其余的字母/数字
i don't think the original person who asked still needs the answer but this thread seems pretty famous and i don't want anyone to waste his time to find what i found the hard way..so
this answer relies primarily on the application provided with the Star Micronics TSP printer
key points:
- reference "Interop.OposPOSPrinter_CCO.dll"
- the printer object should be of type oposposprinter.printer and is initialized in a slightly different way (compared to opos.net)
- the character codes are sent as a string and there's a variable to tell the printer object to use these decimal numbers as character codes
a sample VB.net project with a simple arabic letter converter can be found at https://bitbucket.org/loody/arabic-1001/overview
note: i don't have time to cover the rest of the letters/numbers