当前位置: 澳门新濠3559 > 编程 > 正文

4.流转字符串,4.流转字符串

时间:2019-12-08 22:39来源:编程
1.字符串转比特数组 (1)byte[] bt=System.Text.Encoding.Default.GetBytes("字符串"); (2)byte[] bt=Convert.FromBase64String("字符串"); 2.字符串转流 (1)MemoryStream ms=newMemoryStream(System.Text.Encoding.Default.GetBytes("字符

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);

 

对应

string s = "base64字符串与普通字符串互转";
byte[] bb = System.Text.Encoding.Default.GetBytes(s);
澳门新濠3559,//转成 Base64 形式的 System.String
string sss = Convert.ToBase64String(bb);
byte[] c = Convert.FromBase64String(sss);
string d = System.Text.Encoding.Default.GetString(c);

 

总结:

字符串、字节数组、内存流的转换关系如下图:

澳门新濠3559 1

 

下图增加了Base64String的转换:

澳门新濠3559 2

(2)string str=Convert.ToBase64String(bt);

1.字符串转比特数组

(1)MemoryStream ms=new MemoryStream(bt);

6.比特数组转流

(2)MemoryStream ms=new MemoryStream();ms.Write(bt,0,ms.Length);

(1)byte[] bt=ms.ToArray();

3.流转比特数组

转自:

(2)MemoryStream ms=new MemoryStream();ms.Read(bt,0,bt.Lenght);

(1)string str=Convert.ToBase64String(ms.ToArray());

(1)byte[] bt=System.Text.Encoding.Default.GetBytes("字符串");

5.比特数组转字符串

(2)byte[] bt=Convert.FromBase64String("字符串");

(1)MemoryStream ms=new MemoryStream(System.Text.Encoding.Default.GetBytes("字符串"));

2.字符串转流

(2)MemoryStream ms=new MemoryStream(Convert.FromBase64String("字符串"));

定义string变量为str,内存流变量为ms,比特数组为bt

(2)string str=System.Text.Encoding.Default.GetString(ms.ToArray());

4.流转字符串

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

编辑:编程 本文来源:4.流转字符串,4.流转字符串

关键词: