Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can I remove the need for assigning Chunk and get chars direct from Filestream ?
Dim data(3) As Byte
      Dim Chunk As String
      Using fs As New FileStream(mp3, FileMode.Open)
          Do
              Dim bytesRead = fs.Read(data, 0, 4)
              Chunk = Chr(data(0)) & Chr(data(1)) & Chr(data(2)) & Chr(data(3))
Posted

You are not reading characters, and you are not reading ASCII numbers. You are reading bytes, and nothing else. All files are always made off bytes, no matter if they are text files, or "binary", or anything else.

How you interpret them is up to you, but everything depends on what is actually written in the file, but almost no one in sober mind writes any "ASCII numbers" there. People write either characters or some "binary" objects, such as numbers in their bitwise representations, without any characters. And when characters are written, these days they are often not just one-byte characters; more and more data is written in one or another Unicode UTFs, with UTF-8 being most widely used. And .NET strings are always Unicode strings, other encodings, such as ASCII, are only supported for streams.

So, I'm afraid it could be pointless to ask "how to read ASCII numbers". Chances are, there are no such thins in your files. But if you just use ASCII character encoding in the file, you can simply read characters and type-case each to byte. The numerical value of such byte will be the ASCII value you want. Instead, you are explicitly type-cast 4 bytes to character and still asking why they are characters. :-)

—SA
 
Share this answer
 
v4
Thanks. Ok. Bit more info. The first 3 bytes of the file I'm testing with are are decimal 73, 68 and 51 and variable data contains these.
But I want them as string "ID3" for further processing. The line "Chunk = "
does this but I wonder if there's some method for doing this (perhaps with Filestream) without the need for that line?

This is a convert from VBA where

Dim Chunk As String * 4
Open file For Binary As #ifile
Get ifile, 1, Chunk

fills Chunk with "ID3" and a fourth (unprintable) char.

I'm new to VB Net and Filestream may be the wrong thing for this usage. I don't know.
 
Share this answer
 
Comments
Ralf Meier 17-Jul-15 0:47am    
Don't post a Reply as a Solution ...!
If you want to discuss with (for example SA) then write a comment to his Solution ...
Ralf Meier 17-Jul-15 0:50am    
to your Question :
If you need a special (but re-useable) handling of the input-data you could write a function or method for this ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900