专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »DotNet » gb2312utf8:Asp.net 转换GB2312 的字符串为UTF8编码 »正文

gb2312utf8:Asp.net 转换GB2312 的字符串为UTF8编码

来源: 发布时间:星期日, 2009年8月16日 浏览:7次 评论:0
代码内容:
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(GB2312ToUTF8("大家好欢迎访问 http://www.my400800.cn "));

}

/// <summary>
/// 转换GB2312 串为UTF8编码
/// </summary>
/// <param name="str"></param>
/// <s></s>
public GB2312ToUTF8( str)
{
try
{
Encoding uft8 = Encoding.GetEncoding(65001);
Encoding gb2312 = Encoding.GetEncoding("gb2312");
temp = gb2312.GetBytes(str);
Response.Write("gb2312编码字节个数:" + temp.Length+"<br>");
for ( i = 0; i < temp.Length; i)
{
Response.Write(Convert.ToUInt16(temp[i]). + "<br>");
}
temp1 = Encoding.Convert(gb2312, uft8, temp);
Response.Write("uft8编码字节个数:" + temp1.Length + "<br>");
for ( i = 0; i < temp1.Length; i)
{
Response.Write(Convert.ToUInt16(temp1[i]). + "<br>");
}
result = uft8.GetString(temp1);
result;
}
catch (Exception ex)
{
Response.Write(ex.);
null;
}
}



0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: