Read Utf8 String using BinaryReader - CSharp System.IO

CSharp examples for System.IO:BinaryReader

Description

Read Utf8 String using BinaryReader

Demo Code


using System.Text;
using System.IO;/*from   ww  w.  j av a  2s. com*/

public class Main{
        public static string ReadUtf8String(this BinaryReader br)
        {
            MemoryStream ms = new MemoryStream();
            while (true)
            {
                byte a = br.ReadByte();
                if (a == 0)
                    break;
                ms.WriteByte(a);
            }
            return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length);
        }
}

Related Tutorials