C#和Encoding.ASCII.GetString

编程入门 行业动态 更新时间:2024-10-23 09:29:02
本文介绍了C#和Encoding.ASCII.GetString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 byte[] header = new byte[]{255, 216}; string ascii = Encoding.ASCII.GetString(header);

我希望ASCII等于要FFD8(JPEG SOI标记)

I expect ASCII to be equal to be FFD8 (JPEG SOI marker)

相反,我得到????

推荐答案

在这种情况下,你最好来比较字节数组,而不是转换为字符串。

In this case you'd be better to compare the byte arrays rather than converting to string.

如果您必须转换为字符串,我建议使用编码的Latin-1又名ISO-8859-1又名code 28591页编码,这个编码将映射与十六进制值的所有字节的范围是0-255用相同的十六进制值的统一code字 - 方便了此方案。以下任何方式将得到这个编码方式:

If you must convert to string, I suggest using the encoding Latin-1 aka ISO-8859-1 aka Code Page 28591 encoding, as this encoding will map all bytes with hex values are in the range 0-255 to the Unicode character with the same hex value - convenient for this scenario. Any of the following will get this encoding:

Encoding.GetEncoding(28591) Encoding.GetEncoding("Latin1") Encoding.GetEncoding("ISO-8859-1")

更多推荐

C#和Encoding.ASCII.GetString

本文发布于:2023-11-10 06:22:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Encoding   ASCII   GetString

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!