字符串为byte [],反之亦然? [英] String to byte[] and vice versa?
本文介绍了字符串为byte [],反之亦然?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果
.NET字符串到字节数组C#
我如何将字符串转换为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);
这篇关于字符串为byte [],反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文