Convert Short Array to String C#

c#, utf-16

Solution

You can get a string from a UTF16 byte array using this method:

System.Text.Encoding.Unicode.GetString(bytes)

However, this only accepts an byte array. So you first have to transform your shorts to bytes:

var bytes = a.SelectMany(x => BitConverter.GetBytes(x)).ToArray();

Or slightly more verbose but much more efficient code:

var bytes = new byte[a.Length * 2];
Buffer.BlockCopy(a, 0, bytes, 0, a.Length * 2);

Problem

Is it possible to convert `short` array to `string`, then show the text? ``` short[] a = new short[] {0x33, 0x65, 0x66, 0xE62, 0xE63}; ``` There are `utf16` (thai characters) contains in the array. How can it output and show the thai and english words? Thank you.

Original source