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. hadoop环境搭建及Wordcount案例实验

    1.Linux环境变量设置 在/etc/profile中添加环境变量 sudo vim /etc/profile PATH=$PATH:/usr/local/hadoop/bin source /et ...

  2. MVC Web.Config 配置错误

    配置一个MVC项目的 SessionState,查阅了大量的资料,发现都是直接在web.config中直接加入类似的语句就可以了 <sessionState timeout="60&q ...

  3. C++或C#调用外部exe的分析

    假如有个外部程序名为A.exe,放在目录E:\temp\下,然后我们用C++或者C#写一个程序调用这个A.exe的话(假设这个调用者所在的路径在D:\invoke),通常会采用下面的代码: // C# ...

  4. React Native调试实用技巧,React Native开发者必会的调试技巧

    在做React Native开发时,少不了的需要对React Native程序进行调试.调试程序是每一位开发者的基本功,高效的调试不仅能提高开发效率,也能降低Bug率.本文将向大家分享React Na ...

  5. SUSE12Sp3-Supervisor 守护.net core进程

    1.安装setuptools 将setuptools-0.6c11.tar.gz安装包放到服务器上 tar zxvf setuptools-0.6c11.tar.gz cd setuptools-0. ...

  6. [Swift]LeetCode342. 4的幂 | Power of Four

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example 1: ...

  7. [Swift]LeetCode375. 猜数字大小 II | Guess Number Higher or Lower II

    We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...

  8. [Java]LeetCode690. 员工的重要性 | Employee Importance

    You are given a data structure of employee information, which includes the employee's unique id, his ...

  9. [Swift]LeetCode777. 在LR字符串中交换相邻字符 | Swap Adjacent in LR String

    In a string composed of 'L', 'R', and 'X'characters, like "RXXLRXRXL", a move consists of ...

  10. [Swift]LeetCode980. 不同路径 III | Unique Paths III

    On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square.  There is e ...