Convert a string like '6162636465666768696A6B6C6D6E6F707172737475767778797A' to decimal string like 'abcdefghijklmnopqrstuvwxyz' ONLY UNICODE IN THIS FUNCTION - CSharp System

CSharp examples for System:String Convert

Description

Convert a string like '6162636465666768696A6B6C6D6E6F707172737475767778797A' to decimal string like 'abcdefghijklmnopqrstuvwxyz' ONLY UNICODE IN THIS FUNCTION

Demo Code


using System.Globalization;
using System.Collections;
using System.Text;
using System;//  w  w w  . j a  v a 2s .  c om

public class Main{
        /// <summary>
		/// Convert a string like '6162636465666768696A6B6C6D6E6F707172737475767778797A' to decimal string like 'abcdefghijklmnopqrstuvwxyz'
		/// ONLY UNICODE IN THIS FUNCTION
		/// </summary>
		/// <param name="bufferToManage">String to convert</param>
		/// <returns></returns>
		public static string ConvertHexadecimalStringToUnicodeString (string bufferToManage)
		{
			if (bufferToManage == null)			throw new NolmeArgumentNullException ();

			int		Offset			= 0;
			string	ResultBuffer	= StringUtility.CreateEmptyString ();
			byte[]	TextBytesArray	= new byte [bufferToManage.Length /2];

			for (int i = 0; i < bufferToManage.Length /2; i++)
			{
				TextBytesArray [Offset] = (byte)Int32.Parse(bufferToManage.Substring(i*2,2), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture);
				Offset++;
			}

			char[] AsciiCharacterArray = new char[Encoding.Unicode.GetCharCount(TextBytesArray, 0, TextBytesArray.Length)];
			Encoding.Unicode.GetChars(TextBytesArray, 0, TextBytesArray.Length, AsciiCharacterArray, 0);
			ResultBuffer = new string(AsciiCharacterArray);

			return ResultBuffer;
		}
        public static string CreateEmptyString ()
		{
			return string.Format (CultureInfo.InvariantCulture, "");
		}
}

Related Tutorials