zoukankan      html  css  js  c++  java
  • 字符串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);

  • 相关阅读:
    hbase二级索引学习
    redis-cluster集群Mac部署
    http-flume-kafka.conf
    linux 替换文件中的字符串
    flumeDemo
    redis_exporter监控安装
    Hbase内存磁盘大致关系
    spring cloud 尚硅谷学习
    C10K问题
    navicat 远程链接Mysql问题
  • 原文地址:https://www.cnblogs.com/lwqstyle/p/4702569.html
Copyright © 2011-2022 走看看