byte[]与string相互转换
byte[]转换为字符串存储,然后再转回来
byte[] bytes = System.Text.Encoding.Default.GetBytes("fadfasfasdf"); string str = BitConverter.ToString(bytes); string s2 = BitConverter.ToString(bytes); // 82-C8-EA-17 String[] tempAry = s2.Split("-"); byte[] decBytes2 = new byte[tempAry.Length]; for (int i = 0; i < tempAry.Length; i++) decBytes2[i] = Convert.ToByte(tempAry[i], 16); // decBytes2 same as bytes string s3 = Convert.ToBase64String(bytes); // gsjqFw== byte[] decByte3 = Convert.FromBase64String(s3);
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。