Get Utf8 String from byte array - CSharp System

CSharp examples for System:Byte Array

Description

Get Utf8 String from byte array

Demo Code


using System;/* w ww.  ja va 2  s  .c o  m*/

public class Main{
        static public string GetUtf8String(this byte[] n, UInt32 aStart, uint aCharCount)
        {
            // TODO: This method handles ASCII only currently, no unicode.
            var xChars = new char[aCharCount];
            for (int i = 0; i < aCharCount; i++)
            {
                xChars[i] = (char)n[(aStart) + i];
                if (xChars[i] == 0)
                {
                    return new string(xChars, 0, i);
                }
            }
            return new string(xChars);
        }
}

Related Tutorials