在某一个地方如果是中文会有乱码的情况,是代码问题么?
public static string readHtml(Stream stream)
{
if (stream == null) return "";
string strBuff = "";
byte[] bytes = new byte[256];
int byteRead = 0;
byteRead = stream.Read(bytes, 0, 256);
while (byteRead != 0)
{
string strResp = Encoding.GetEncoding("gb2312").GetString(bytes, 0, byteRead);
strBuff = strBuff + strResp;
byteRead = stream.Read(bytes, 0, 256);
}
return strBuff;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
我找到的解决办法,先全部读到内存流中,然后转为字符就OK了。
public static string readHtml(Stream stream)
{
if (stream == null) return "";
MemoryStream destination = new MemoryStream();
stream.CopyTo(destination);
stream.Close();
return Encoding.GetEncoding("gb2312").GetString(destination.ToArray());
}
######是coding的问题######
gb2312 变成utf-8呢