zoukankan      html  css  js  c++  java
  • UTF8转GB2312

    公司有个项目需要跟别的系统互通,新做的是utf-8编码的,另一个是gb2312的,需要把utf-8编码转为gb2312。写了下面的代码:
            public string UTF8toGB2312(string str)
            
    {
                
    string utfStr = str;
                
    byte[] utfBytes = System.Text.Encoding.UTF8.GetBytes(utfStr);
                
    byte[] gbBytes = System.Text.Encoding.Convert(System.Text.Encoding.UTF8,System.Text.Encoding.GetEncoding("gb2312"),utfBytes);
                
    char[] asciiChars = new char[System.Text.Encoding.GetEncoding("gb2312").GetCharCount(gbBytes, 0, gbBytes.Length)];
                System.Text.Encoding.GetEncoding(
    "gb2312").GetChars(gbBytes, 0, gbBytes.Length, asciiChars, 0);
                
    string gbStr = new string(asciiChars);
                
    return gbStr;
            }
    可惜转来转去不成功啊,郁闷了~
    最后没办法,把新做的这一页单独转成了gb2312的,在load里添加:
    if (!IsPostBack)
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");

    各位高人帮忙看看上面的那段代码怎么不成功呢?

  • 相关阅读:
    龙威零式_团队项目例会记录_12
    龙威零式_团队项目例会记录_11
    龙威零式_团队项目例会记录_10
    个人项目--词频统计
    四人小组-----车辆管理系统+员工管理
    效能分析
    结对编程体会
    累计进度条 PSP 饼图
    词频统计更新
    四人项目设计
  • 原文地址:https://www.cnblogs.com/vagerent/p/805740.html
Copyright © 2011-2022 走看看