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

CSharp examples for System:String Convert

Description

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

Demo Code


using System.Globalization;
using System.Collections;
using System.Text;
using System;// w w w .jav a2s .c om

public class Main{
        #endregion

		#region Convert string to decimal & decimal to string
		/// <summary>
		/// Convert a string like 'abcdefghijklmnopqrstuvwxyz' to decimal string like '6162636465666768696A6B6C6D6E6F707172737475767778797A'
		/// ONLY UNICODE IN THIS FUNCTION
		/// </summary>
		/// <param name="bufferToManage">String to convert</param>
		/// <returns></returns>
		public static string ConvertUnicodeStringToHexadecimalString (string bufferToManage)
		{
			byte[] TextBytesArray	= Encoding.Unicode.GetBytes(bufferToManage);

			/*
			string ResultBuffer		= StringUtility.CreateEmptyString ();
			foreach (byte a in TextBytesArray)
			{
				if (a<16)
					ResultBuffer += "0" + a.ToString ("X", CultureInfo.InvariantCulture);
				else
					ResultBuffer += a.ToString ("X", CultureInfo.InvariantCulture);
			}
			return ResultBuffer;
			*/
			StringBuilder LocalStringBuilder = new StringBuilder();
			foreach (byte a in TextBytesArray)
			{
				string TemporaryBuffer;
				if (a<16)
					TemporaryBuffer = "0" + a.ToString ("X", CultureInfo.InvariantCulture);
				else
					TemporaryBuffer = a.ToString ("X", CultureInfo.InvariantCulture);
				LocalStringBuilder.Append (TemporaryBuffer);
			}
			return LocalStringBuilder.ToString ();
		}
}

Related Tutorials