您现在的位置:龙卷风首页 ›› 网络编程 ›› 阅读文章

asp.net中string和byte[]转换

byte数组跟string互相转换

byte[] byteArray = System.Text.Encoding.Default.GetBytes( str );

反过来也是一样,把byte[]转成string:

string str = System.Text.Encoding.Default.GetString( byteArray );

其实,在System.Text.Encoding class中,还有很多其它有用的方法,像GetChars,从一个byte[]转成一个char[],等等,可以参考MSDN。
另外,还有其它编码方式的,如System.Text.UTF8Encoding class、System.Text.UnicodeEncoding class等,根据不同需要可选不同的class。

 

来源:http://www.cnblogs.com/baishahe/archive/2008/03/21/1115919.html

作者 不见不散 本文仅代表作者观点,与龙卷风资讯网立场无关。

我来说两句

内容/Content