Posts Tagged BinaryReader

Reading a line from a BinaryReader

Posted by Ozer Senturk on Tuesday, 9 March, 2010
/// <summary>
/// Reads a line from binary reader br
/// </summary>
/// <param name="br">Binary reader to read a line from</param>
/// <returns>The line that is read from br</returns>
public static string readLine(BinaryReader br)
{
    string s = "";
    try
    {
        do
        {
            byte b = br.ReadByte();
            char c = (char)b;
            s += c;

            if (c == '\n')
                return s;

        } while (true);
    }
    catch (Exception)
    {
        return s;
    }
}