可能重复:
.NET 字符串到字节数组 C#
如何将 String 转换为 byte[] 数组,反之亦然?我需要将字符串存储在一些二进制存储中.请在两个方向显示示例.还有一件事:每个字符串可能大于 90Kb.
How do I convert String to byte[] array and vice versa? I need strings to be stored in some binary storage. Please show example in both directions. And one more thing: each string maybe bigger than 90Kb.
如果要使用UTF-8编码:
If you want to use UTF-8 encoding:
// string to byte[]
byte[] bytes = Encoding.UTF8.GetBytes(someString);
// byte[] to string
string anotherString = Encoding.UTF8.GetString(bytes);
这篇关于字符串到字节[],反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!