Convert UTF-8 and ASCII encoded bytes back to UTF-16 encoded string

发布时间:2017-3-24 14:06:48 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"Convert UTF-8 and ASCII encoded bytes back to UTF-16 encoded string",主要涉及到Convert UTF-8 and ASCII encoded bytes back to UTF-16 encoded string方面的内容,对于Convert UTF-8 and ASCII encoded bytes back to UTF-16 encoded string感兴趣的同学可以参考一下。

最近手上在做一个项目,涉及到了编码问题,查了不少资料。看到一些好的资料,留下做记录。 共享一篇国外的关于转码的文章 原文章地址:http://www.sourcecode3s.com/ccsharp/FileStream/Convert_UTF-8_and_ASCII_encoded_bytes_back_to_UTF-16_encoded_string_12273.aspx using System; using System.IO; using System.Text; class Test { public static void Main() { using (StreamWriter output = new StreamWriter("practice.txt")) { // Create and write a string containing the symbol for Pi. string srcString = "Area = \u03A0r^2"; // Convert the UTF-16 encoded source string to UTF-8 and ASCII. byte[] utf8String = Encoding.UTF8.GetBytes(srcString); byte[] asciiString = Encoding.ASCII.GetBytes(srcString); // Write the UTF-8 and ASCII encoded byte arrays. output.WriteLine("UTF-8 Bytes: {0}", BitConverter.ToString(utf8String)); output.WriteLine("ASCII Bytes: {0}", BitConverter.ToString(asciiString)); // Convert UTF-8 and ASCII encoded bytes back to UTF-16 encoded // string and write. output.WriteLine("UTF-8 Text : {0}", Encoding.UTF8.GetString(utf8String)); output.WriteLine("ASCII Text : {0}", Encoding.ASCII.GetString(asciiString)); Console.WriteLine(Encoding.UTF8.GetString(utf8String)); Console.WriteLine(Encoding.ASCII.GetString(asciiString)); } } }

上一篇:Maven中Profiles的应用(1)
下一篇:web应用打war包

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款