先将stirng s 转换成byte[]存放到source中,在将source中的byte拷贝source.Length个到destin中。
string s = "test string";
byte[] source = new byte[ 100 ];
bute[] destin = new byte[ 512 ];
source = System.Text.Encoding.Unicode.GetBytes( s );
System.Array.Copy( source, destin, source.Length );
bytes 转换成 string:
s = System.Text.Encoding.Unicode.GetString( destin, 0, destin.Length )
本文介绍了如何将字符串转换为字节数组并存储,再将字节数组转换回字符串的方法。首先使用Unicode编码将字符串转为byte[],然后通过Array.Copy()方法复制到另一个更大的byte[]中保存。最后从保存的byte[]中读取并还原成原始的字符串。
607

被折叠的 条评论
为什么被折叠?



