游戏开发,系统架构; 博客迁移到:http://www.jianshu.com/u/3ac0504b3b8c
全部博文(198)
分类: 嵌入式
2011-10-31 15:21:44
字符串string和内存流MemoryStream及比特数组byte[]互转比较
定义string变量为str,内存流变量为ms,比特数组为bt
1.字符串转比特数组
(1)byte[] bt=System.Text.Encoding.Default.GetBytes("字符串");
(2)byte[] bt=Convert.FromBase64String("字符串");
2.字符串转流
(1)MemoryStream ms=new MemoryStream(System.Text.Encoding.Default.GetBytes("字符串"));
(2)MemoryStream ms=new MemoryStream(Convert.FromBase64String("字符串"));
3.流转比特数组
(1)byte[] bt=ms.ToArray();
(2)MemoryStream ms=new MemoryStream();ms.Write(bt,0,ms.Length);
4.流转字符串
(1)string str=Convert.ToBase64String(ms.ToArray());
(2)string str=System.Text.Encoding.Default.GetString(ms.ToArray());
5.比特数组转字符串
(1)string str=System.Text.Encoding.Default.GetString(bt);
(2)string str=Convert.ToBase64String(bt);
6.比特数组转流
(1)MemoryStream ms=new MemoryStream(bt);
(2)MemoryStream ms=new MemoryStream();ms.Read(bt,0,bt.Lenght);
可以看出byte[]比较活跃在string和流转化时是个重要的桥梁
GS_googleAddAdSenseService("ca-pub-1133838214619276"); GS_googleEnableAllServices(); GA_googleAddSlot("ca-pub-1133838214619276", "blogbus_user_detail"); GA_googleFetchAds(); 转载地址:http://hcup.blogbus.com/logs/37009266.html