广告合作
  • 今日头条

    今日头条

  • 百度一下

    百度一下,你就知道

  • 新浪网

    新浪网 - 提供新闻线索,重大新闻爆料

  • 搜狐

    搜狐

  • 豆瓣

    豆瓣

  • 百度贴吧

    百度贴吧——全球领先的中文社区

  • 首页 尚未审核订阅工具 订阅

    C# char[] 转换为 byte[]

    来源:网络收集  点击:  时间:2024-02-27
    【导读】:
    动态空间分配将char转换为byte,不管什么encoding,各种方法都试过,只能硬转换工具/原料morevs2010consoleapplication方法/步骤1/5分步阅读

    新建一个控制台项目

    2/5

    写主函数

    static void Main(string args) { string c=; c = Console.ReadLine(); char p = c.ToCharArray(); byte pb = new byte; Listbyte ls= new Listbyte(); alloc(ls, p,64); FileStream fs = new FileStream(D:\\abc.txt, FileMode.OpenOrCreate); BinaryWriter sw = new BinaryWriter(fs); sw.Write(ls.ToArray()); sw.Close(); fs.Close();

    }

    3/5

    写alloc

    public static int alloc(Listbyte bytes,char p,int block) { for (int i=0;ip.Length ;i++ ) { bytes.Add((byte)p); } while (bytes.Count % block != 0) { bytes.Add(0); } return bytes.Count/block; }

    4/5

    运行测试一下

    5/5

    打开txt

    注意事项

    用了list

    动态分配大小为64,自己看着随意改

    char
    本文关键词:

    版权声明:

    1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。

    2、本站仅提供信息发布平台,不承担相关法律责任。

    3、若侵犯您的版权或隐私,请联系本站管理员删除。

    4、文章链接:http://www.1haoku.cn/art_157640.html

    相关资讯

    ©2019-2020 http://www.1haoku.cn/ 国ICP备20009186号05-06 16:38:40  耗时:0.026
    0.0258s