System.Text.Encoding.UTF8.GetBytes额外的字节 [英] System.Text.Encoding.UTF8.GetBytes Extra Byte

查看:1005
本文介绍了System.Text.Encoding.UTF8.GetBytes额外的字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这行

System.Text.Encoding.UTF8.GetBytes("ABCD±ABCD")

给我回10个字节,而不是9? 虽然±是CHAR(177)

Give me back 10 bytes instead of 9? Although ± is char(177)

有一个.net功能/编码,将转换此字符串的正确到9个字节?

Is there a .Net function / encoding that will translate this string correctly into 9 bytes?

推荐答案

您应该使用的Windows 1251 编码获得± 177

You should use Windows-1251 encoding to get ± as 177

var bytes = System.Text.Encoding.GetEncoding("Windows-1251").GetBytes("ABCD±ABCD");

这篇关于System.Text.Encoding.UTF8.GetBytes额外的字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆