none
Convert hex to character

    Question

  • Hi.

    I have a string of hexadecimals that i whant to convert into text that i can view in

    a textbox or a listbox.


    Ex

    string myHex = "062306340634";

     

    Best regards Surfsune


     

    Wednesday, June 21, 2006 10:49 AM

Answers

  • for something like that you need to loop through the character array and process it yourself.

                char[] myHex = new char[4] { '\x0633', '\x0643', '\x0627', '\u0646' };
                string str = "";

                foreach (char ch in myHex)
                {
                    str += string.Format(@"\x{0:x4}", (int)ch);
                }

    Wednesday, June 21, 2006 4:42 PM

All replies

  • A string is already text.

     

    TextBox.Text = myHex;

    Wednesday, June 21, 2006 2:32 PM
  • Ok

    Forget the string value then. How do i convert a hex value to text.

    This exampe works.

    char[] myHex = new char[4] { '\x0633', '\x0643', '\x0627', '\u0646' };

    string str = new String(myHex);

    label2.Text = str.ToString();

     

    The problem is, my hex value i not formatted like this \x0633\x0643\

    It´s more like this "0633063430627"

     

     

    Wednesday, June 21, 2006 2:51 PM
  • for something like that you need to loop through the character array and process it yourself.

                char[] myHex = new char[4] { '\x0633', '\x0643', '\x0627', '\u0646' };
                string str = "";

                foreach (char ch in myHex)
                {
                    str += string.Format(@"\x{0:x4}", (int)ch);
                }

    Wednesday, June 21, 2006 4:42 PM
  • Hey,
    Are you sure this is a hex value?
    In case you want to, you use this Hexadecimal to String Online Tool
    Cheers,
    David
    Friday, November 20, 2009 2:32 PM
  • You have a string like "062306340634" and you want to convert it to "\u0623\u0634\u0634"?

    string myHex = "062306340634";

    string str = "";
    for(int i=0; i<myHex.Length; i+=4)
        str += (char)Int16.Parse(myHex.Substring(i, 4), NumberStyles.AllowHexSpecifier);
    • Proposed as answer by Vihang Shah Tuesday, August 07, 2012 6:20 AM
    Monday, November 23, 2009 10:46 AM
  • You have a string like "062306340634" and you want to convert it to "\u0623\u0634\u0634"?

    string myHex = "062306340634";

    string str = "";
    for(int i=0; i<myHex.Length; i+=4)
        str += (char)Int16.Parse(myHex.Substring(i, 4), NumberStyles.AllowHexSpecifier);

    This answer is more compact and reliable.. Thanks Louis for the excellent solution.

    Thanks,

    @VHNG


    Programing & Research leads to inventions.
    http://vihang-shah.blogspot.com/

    Tuesday, August 07, 2012 6:22 AM
  • Hey,
    Are you sure this is a hex value?
    In case you want to, you use this Hexadecimal to String Online Tool
    Cheers,
    David

    Thank you so much for the online convertor.

    Programing & Research leads to inventions.
    http://vihang-shah.blogspot.com/

    Tuesday, August 07, 2012 6:25 AM