zoukankan      html  css  js  c++  java
  • asp.net 转换GB2312 的字符串为UTF8编码

     /// <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>
        /// <returns></returns>
        public string GB2312ToUTF8(string str)
        {
            try
            {
                Encoding uft8 = Encoding.GetEncoding(65001);
                Encoding gb2312 = Encoding.GetEncoding("gb2312");
                byte[] temp = gb2312.GetBytes(str);
                Response.Write("gb2312的编码的字节个数:" + temp.Length+"<br>");
                for (int i = 0; i < temp.Length; i++)
                {
                    Response.Write(Convert.ToUInt16(temp[i]).ToString() + "<br>");
                }
                byte[] temp1 = Encoding.Convert(gb2312, uft8, temp);
                Response.Write("uft8的编码的字节个数:" + temp1.Length + "<br>");
                for (int i = 0; i < temp1.Length; i++)
                {
                    Response.Write(Convert.ToUInt16(temp1[i]).ToString() + "<br>");
                }
                string result = uft8.GetString(temp1);
                return result;
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
                return null;
            }
        }

  • 相关阅读:
    nput keyup 500ms 延时输入 事件处理
    browser-sync默认地址如何转成127.0.0.1
    overflow:scroll-css知识备忘
    圆角的css样式
    支付宝开发
    C#代码与javaScript函数的相互调用
    高性能web开发 如何加载JS,JS应该放在什么位置?
    Makefile自动生成头文件依赖
    一步步教你如何写Makefile
    (一):U-BOOT启动分析--概述
  • 原文地址:https://www.cnblogs.com/jishu/p/1940111.html
Copyright © 2011-2022 走看看