gpt4 book ai didi

c#将字节转换为字符串并写入txt文件

转载 作者:行者123 更新时间:2023-11-30 13:27:14 24 4
gpt4 key购买 nike

我如何转换 byte[] b = new byte[1]; b[1]=255 到字符串?我需要一个值为“255”的字符串变量 string text= "255";然后将其存储在文本文件中?

最佳答案

从字节开始:

        byte[] b = new byte[255];
string s = Encoding.UTF8.GetString(b);
File.WriteAllText("myFile.txt", s);

如果你从字符串开始:

        string x = "255";
byte[] y = Encoding.UTF8.GetBytes(x);
File.WriteAllBytes("myFile2.txt", y);

关于c#将字节转换为字符串并写入txt文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13502978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com