Will return the ANSI string stored in the buffer - CSharp System

CSharp examples for System:String Encode Decode

Description

Will return the ANSI string stored in the buffer

Demo Code


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

public class Main{
        public static string ReadAnsiString(byte[] buffer, ref int offset, int count)
        {
            offset += count;
            return ReadAnsiString(buffer, offset - count, count);
        }
        /// <summary>
        /// Will return the ANSI string stored in the buffer
        /// </summary>
        public static string ReadAnsiString(byte[] buffer, int offset, int count)
        {
            // ASCIIEncoding.ASCII.GetString will convert some values to '?' (byte value of 63)
            // Any codepage will do, but the only one that Mono supports is 28591.
            return ASCIIEncoding.GetEncoding(28591).GetString(buffer, offset, count);
        }
}

Related Tutorials