Write Unicode using BinaryWriter - CSharp System.IO

CSharp examples for System.IO:BinaryWriter

Description

Write Unicode using BinaryWriter

Demo Code


using System.Text;
using System.IO;/*ww w.ja  v a 2  s. com*/
using System;

public class Main{
        public static void WriteUnicode(this BinaryWriter writer, string text, int len)
        {
            byte[] unicode = Encoding.Unicode.GetBytes(text);
            byte[] result = new byte[len * 2];
            int max = len * 2 - 2;
            Array.Copy(unicode, result, unicode.Length > max ? max : unicode.Length);
            writer.Write(result);
        }
}

Related Tutorials