Decodes the buffer using the specified encoding, stopping at the first null - CSharp System

CSharp examples for System:Array Null Element

Description

Decodes the buffer using the specified encoding, stopping at the first null

Demo Code


using System.Text;
using System.Collections.Generic;
using System;//from w w w .j  a  v a2 s. c  o  m

public class Main{
        /// <summary>
        /// Decodes the buffer using the specified encoding, stopping at the first null
        /// </summary>
        public static string DecodeAsString(byte[] buffer, int offset, int length, Encoding encoding)
        {
            for (int n = 0; n < length; n++)
            {
                if (buffer[offset + n] == 0)
                    length = n;
            }
            return encoding.GetString(buffer, offset, length);
        }
}

Related Tutorials