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);
 
 
总结:
字符串、字节数组、内存流的转换关系如下图:

下图增加了Base64String的转换:

 

字符串string 、byte[]、MemoryStream、Base64String的相互转换的更多相关文章

  1. Java中字符串和byte数组之间的相互转换

    1.将字符转换成byte数组 String str = "罗长"; byte[] sb = str.getBytes(); 2.将byte数组转换成字符 byte[] b={(by ...

  2. 字符串string和内存流MemoryStream及比特数组byte[]互转

    原文:字符串string和内存流MemoryStream及比特数组byte[]互转   字符串string和内存流MemoryStream及比特数组byte[]互转比较 定义string变量为str, ...

  3. c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换

    字节数组byte[]与图片image之间的转化 字节数组转换成图片 public static Image byte2img(byte[] buffer) { MemoryStream ms = ne ...

  4. C# 字符串string和内存流MemoryStream及比特数组byte[]之间相互转换

    定义string变量为str,内存流变量为ms,比特数组为bt 1.字符串转比特数组 复制代码 代码如下: (1)byte[] bt=System.Text.Encoding.Default.GetB ...

  5. C#中字节数组byte[]和字符串string类型的相互转换

    C#中字节数组byte[]和字符串string类型的相互转换: string转byte[]: byte[] byteArray = System.Text.Encoding.Default.GetBy ...

  6. byte转换字符串(string)+字符串转换byte

    C# 中字符串string和字节数组byte[]的转换 //string转byte[]: byte[] byteArray = System.Text.Encoding.Default.GetByte ...

  7. C# string byte[] Base64 常用互相转换

    参考: http://www.cnblogs.com/zxx193/p/3605238.html?utm_source=tuicool http://www.cnblogs.com/freeliver ...

  8. byte与base64string的相互转化以及加密算法

    //在C#中 //图片到byte[]再到base64string的转换: Bitmap bmp = new Bitmap(filepath); MemoryStream ms = new Memory ...

  9. .net字符串Gzip压缩和base64string转换:

    class Program { static void Main(string[] args) { //要压缩的字符串 string data = "13800138000,验证码:1234 ...

随机推荐

  1. IEnumerabl 和 IEnumertator

    public interface IEnumerable   {       IEnumerator GetEnumerator();   }   IEnumerator 接口 public inte ...

  2. gym 101628

    前几天感冒了三天没怎么写题...今天好很多了打个三星场找点手感. 不行啊我好菜啊.只会8个..补题的话,再说吧.G题感觉值得一补. 补了G,K不想写B不会. 说实话这个三星场还是很新人向的,知识点也蛮 ...

  3. Maven插件一览

    maven-assembly-plugin 将对应模块依赖在  mvn package 阶段全部打到一个 jar 包里面: java -cp xx.jar package.name.MainClass ...

  4. nodejs内存溢出

    npm-v 报错,错误信息如下: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScri ...

  5. 网页开发--03(wampserver安装服务无法启动的问题)

    一.安装wampserver 一路next,指定安装路径外,其它默认安装. 二.我遇到的问题 当任务图标绿色为正常启动状态,但是我的从打开一直是黄色,问题在于Apache和MySql 1)Apache ...

  6. Jenkins在shell脚本运行docker权限报错解决

    报错环境 系统信息 Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS Release: 16.04 Codename: xenial doc ...

  7. [Swift]LeetCode104. 二叉树的最大深度 | Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  8. [Swift]LeetCode126. 单词接龙 II | Word Ladder II

    Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformat ...

  9. [Swift]LeetCode246.对称数 $ Strobogrammatic Number

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  10. [Swift]LeetCode371. 两整数之和 | Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...