标签:
string s = "test";
//Convert from string to byte[]
//byte[] bytes = Convert.FromBase64String(s);
byte[] bytes = Encoding.UTF8.GetBytes(s);
//Convert from byte[] to String
//string s2 = Convert.ToBase64String(bytes);
string s2 = Encoding.UTF8.GetString(bytes);
Console.WriteLine(s2);
问题:
当用Encoding.UTF8从byte[]转为string再转回byte[]时,内容有改变;而Convert.FromBase64String和Convert.ToBase64String保持了原内容的一致。
原因:
后补。好像和编码数量有关系。
C# Tips: String Convert to byte[]
标签:
原文地址:http://www.cnblogs.com/jane850113/p/5843162.html