C#中文乱码解决:UTF8 转 UNICODE
来源:互联网 发布:企业域名邮箱 编辑:程序博客网 时间:2024/05/22 03:45
XML文件可以采用多种编码,但是经过不同的编码后对于中文会出现乱码问题,比如“骞垮憡涓戦椈”,对于此问题的解决如下:
//方法一: static void Main() { string utf8String = "骞垮憡涓戦椈"; // Create two different encodings. Encoding utf8= Encoding.UTF8; Encoding defaultCode= Encoding.Default; // Convert the string into a byte[]. byte[] utf8Bytes = default.GetBytes(utf8String ); // Perform the conversion from one encoding to the other. byte[] defaultBytes = Encoding.Convert(utf8, defaultCode, utf8Bytes ); // Convert the new byte[] into a char[] and then into a string. // This is a slightly different approach to converting to illustrate // the use of GetCharCount/GetChars. char[] defaultChars = new char[defaultCode.GetCharCount(defaultBytes , 0, defaultBytes .Length)]; defaultCode.GetChars(defaultBytes , 0, defaultBytes .Length, defaultChars , 0); string defaultString = new string(defaultChars ); // Display the strings created before and after the conversion. Console.WriteLine("Original string: {0}", utf8String); Console.WriteLine("Ascii converted string: {0}", defaultString); }//或者方法二: byte[] buffer1 = Encoding.Default.GetBytes(utf8String ); byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length); string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
- C#中文乱码解决:UTF8 转 UNICODE
- qt5 unicode 转中文 utf8
- utf8解决JSP中文乱码问题
- mysql utf8设置,解决中文乱码
- utf8解决JSP中文乱码问题
- perl 解决mysql utf8中文乱码 问题
- ios utf8乱码转中文
- 汉字乱码 UTF8 UNICODE
- C#中文乱码解决
- C#字符转之UTF8转成Unicode
- C# unicode utf8 转码
- 中文乱码解决及中文编码成UTF8
- c#中文转unicode
- C#中文转Unicode、Unicode转中文
- C#解决cookie中文乱码
- mysql_query("SET NAMES 'utf8'",$link);解决php中文乱码
- C+++Utf8字符转换Gb2312编码,解决TinyXml中文乱码
- Windows下MySQL UTF8 编码设置(解决中文乱码)
- C语言初探 之 %p
- Perl LWP&HTTP
- 【pig】pig的vim高亮设置
- html中嵌套FLASH
- Android播放视频(二)
- C#中文乱码解决:UTF8 转 UNICODE
- The Language ⇔ Language Matrix
- 美国人气哭了:中国人竟然如此入侵美国
- iphone上下左右手势判断代码
- Android播放视频(一)
- VB MSFlexGrid控件的几种使用方法
- DFS走迷宫
- 通过LDAP验证Active Directory服务
- html 学习 引用