流读取器.读取字符数 [英] Stream reader.Read number of character
问题描述
是否有任何Stream读取器类从 string
中仅读取 char
或从 byte []
中的 byte
>?
Is there any Stream reader Class to read only number of char
from string
Or byte
from byte[]
?
例如读取字符串:
string chunk = streamReader.ReadChars(5); // Read next 5 chars
或读取字节
byte[] bytes = streamReader.ReadBytes(5); // Read next 5 bytes
请注意,此方法的返回类型或类的名称无关紧要.我只想知道是否有类似的东西,那么我可以使用它.
Note that the return type of this method or name of the class does not matter. I just want to know if there is some thing similar to this then i can use it.
我从midi File中获得了 byte []
.我想用C#读取此midi文件.但是我需要能够读取字节数.或字符(如果我将其转换为十六进制).要验证Midi并更轻松地从中读取数据.
I have byte[]
from midi File. I want to Read this midi file in C#. But i need ability to read number of bytes. or chars(if i convert it to hex). To validate midi and read data from it more easily.
推荐答案
感谢您的评论.我不知道读取方法有重载.我可以使用FileStream实现这一点.
Thanks for the comments. I didnt know there is an Overload for Read Methods. i could achieve this with FileStream.
using (FileStream fileStream = new FileStream(path, FileMode.Open))
{
byte[] chunk = new byte[4];
fileStream.Read(chunk, 0, 4);
string hexLetters = BitConverter.ToString(chunk); // 4 Hex Letters that i need!
}
这篇关于流读取器.读取字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!