String To Hex - CSharp System

CSharp examples for System:Hex

Description

String To Hex

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from ww  w.j a  va  2  s  . co  m

public class Main{
        public static string ToHex(this string str)
        {
            StringBuilder sb = new StringBuilder();

            foreach (int charCode in str)
            {
                string hex1 = Convert.ToString(charCode, 16);
                string hex = hex1.PadLeft(2, '0');
                sb.Append(hex);
            }

            return sb.ToString();
        }
}

Related Tutorials