Here I will post problems I and my colleagues met and solutions we found.

Friday, January 20, 2006

Reading text from file

I didn't touch .NET for several months, because my current work is not connected to it. But recently I wanted to make small program for myself, reading TAG from MP3 file.

Well, I spent some time figuring out how to do it properly. My final approach at this point looks like this.


System.IO.Stream stream is parameter

byte[] buffer = new byte[30];
System.Text.Encoding enc = System.Text.Encoding.GetEncoding(0);
if (!enc.IsSingleByte)
enc = System.Text.Encoding.ASCII;
stream.Read(buffer, 0, 30);
title = enc.GetString(buffer).TrimEnd('\0');

No comments: