1、首先我们需要引入:using System.Text; 2、 GB2312转化为UTF-8:
- string LanChange(string str)
- {
- Encoding utf8;
- Encoding gb2312;
- utf8 = Encoding.GetEncoding("UTF-8");
- gb2312 = Encoding.GetEncoding("GB2312");
- byte[] gb = gb2312.GetBytes(str);
- gb = Encoding.Convert(gb2312,utf8,gb);
- return utf8.GetString(gb);
- }
复制代码 3、UTF-8转化为GB2312
- string ChangeLan(string text)
- {
- byte[] bs = Encoding.GetEncoding("UTF-8").GetBytes(text);
- bs = Encoding.Convert(Encoding.GetEncoding("UTF-8"), Encoding.GetEncoding("GB2312"), bs);
- return Encoding.GetEncoding("GB2312").GetString(bs);
- }
复制代码
|