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");

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

  • 相关阅读:
    Camera HAL3学习
    Android GPU呈现模式分析
    Android O版本自定义日志输出目录
    Android Configstore HAL
    Ubuntu下设置adb path的方法
    Ubuntu使用技巧
    PHP学习笔记
    mysql安装
    在ubuntu中安装Python
    OS X在使用<semaphore.h>时报错
  • 原文地址:https://www.cnblogs.com/vagerent/p/805740.html
Copyright © 2011-2022 走看看