`
baiwenwo
  • 浏览: 66069 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

c#_string与byte[]之间的转换

阅读更多

先将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 )

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics