System.Text.Encoding.UTF8 字符串和字节数组的互相转换


/*--===------------------------------------------===--
so lang to write code , now i'm free to code again,ha.
this time, let's see a demo, Encoding.
xuminghui, 2008-05-14 @home
--===------------------------------------------===---
*/


namespace xumh
{
    
public class EncodingTest
    
{
        
public static void Main()
        
{
            System.Console.Write(
"Input String, test Encoding:");
            
string input = System.Console.ReadLine();
            
//here, get the Byte Array of the String
            byte[] encodeBytes = System.Text.Encoding.UTF8.GetBytes(input);
            System.Console.WriteLine(
"Encoding Bytes:{0}",System.BitConverter.ToString(encodeBytes));
            
//here, get the String of the Bytes
            string gets = System.Text.Encoding.UTF8.GetString(encodeBytes);
            System.Console.WriteLine(
"Encoding String:{0}",gets);
            System.Console.ReadLine();
        }

    }

}
原文地址:https://www.cnblogs.com/flaaash/p/1197265.html