C#中string與byte[]格式互轉

實現功能:

1,string轉byte[]格式

2,byte[]格式轉成string格式

轉換代碼如下:


//byte[]格式轉成string格式
stringstr = Encoding.UTF8.GetString(bytes)

//string轉byte[]格式
bytes = Encoding.Default.GetBytes(str)


原文鏈接:C#中string與byte[]格式互轉