Get Bytes UTF8 from String - CSharp System

CSharp examples for System:Byte

Description

Get Bytes UTF8 from String

Demo Code


using System.Text;
using System.Collections.Generic;
using System.Collections;
using System;//from   www  .j  av a  2 s.com

public class Main{
        public static byte[] GetBytesUTF8(this string str)
        {
            if (str == null)
                return new byte[0];

            UTF8Encoding enc = new UTF8Encoding();
            return enc.GetBytes(str);
        }
        public static byte[] GetBytes(this string str)
        {
            if (str == null)
                return new byte[0];

            ASCIIEncoding enc = new ASCIIEncoding();
            return enc.GetBytes(str);
        }
}

Related Tutorials