C#:将字节数组转换为字符串并输出到控制台 [英] C#: Converting byte array to string and printing out to console
本文介绍了C#:将字节数组转换为字符串并输出到控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void parse_table(BinaryReader inFile)
{
byte[] idstring = inFile.ReadBytes(6);
Console.WriteLine(Convert.ToString(idstring));
}
这是一个简单的代码段:读取文件的前6个字节并将其转换为字符串。
It is a simple snippet: read the first 6 bytes of the file and convert that to a string.
但是控制台显示 System.Byte []
。
也许我使用了错误的类进行转换。我应该使用什么?最终它将解析UTF-8编码的文件名,我打算使用相同的方法读取所有文件名。
Maybe I'm using the wrong class for conversion. What should I be using? It will eventually be parsing filenames encoded in UTF-8, and I'm planning to use the same method to read all filenames.
推荐答案
实际上是:
Console.WriteLine(Encoding.Default.GetString(value));
或针对UTF-8:
Console.WriteLine(Encoding.UTF8.GetString(value));
这篇关于C#:将字节数组转换为字符串并输出到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文