none
Convert byte to ASCII

    Question

  • hi,

    How to convert byte array  to ASCII in VB.NET

    System.Text.Encoding.ASCII.Getstring(y)

    it gives the data like 52414D41 .

    but i need "RAMA"  instead of 52414D41.

    How? Any help?

    Thank U!

    Wednesday, June 14, 2006 5:40 AM

Answers

  • Based on your result "53414D41", I assume that your array contains this hexadecimal bytes (&H52, &H41, &H4D, &H41). If this is the case, then you can convert it to string with either the default encoding or UTF8 encoding:



    Dim s As String = System.Text.Encoding.UTF8.GetString( bytearray )

     


    or



    Dim s As String = System.Text.Encoding.Default.GetString( bytearray )

     


    Hope this helps,

    -chris
    Thursday, June 15, 2006 3:34 AM
  •  Chris Vega wrote:
    Based on your result "53414D41", I assume that your array contains this hexadecimal bytes (&H52, &H41, &H4D, &H41).

    If it did, Encoding.ASCII.GetString would return the expected output "RAMA", not "52414D41".

     

    Thursday, June 15, 2006 7:06 AM

All replies

  • What does your y variable contain?

     

    Wednesday, June 14, 2006 6:49 AM
  • Based on your result "53414D41", I assume that your array contains this hexadecimal bytes (&H52, &H41, &H4D, &H41). If this is the case, then you can convert it to string with either the default encoding or UTF8 encoding:



    Dim s As String = System.Text.Encoding.UTF8.GetString( bytearray )

     


    or



    Dim s As String = System.Text.Encoding.Default.GetString( bytearray )

     


    Hope this helps,

    -chris
    Thursday, June 15, 2006 3:34 AM
  •  Chris Vega wrote:
    Based on your result "53414D41", I assume that your array contains this hexadecimal bytes (&H52, &H41, &H4D, &H41).

    If it did, Encoding.ASCII.GetString would return the expected output "RAMA", not "52414D41".

     

    Thursday, June 15, 2006 7:06 AM
  • You're right., I can't think of any other reason why he is getting the hexadecimal representation of his byte array.

    -chris
    Thursday, June 15, 2006 7:25 AM
  • ...WOW!! Absolutely Aazingg.... Thank you soooo much! You won't believe how much i had to search the net for this simple Answer. Im working on a BIG project in VB.net and I promise Chris, whatever money I get, a chunk of it is YOurs!!!!
    Thursday, October 08, 2009 7:23 PM
  • Could the source byte array actually be  &h35 &h33 &h34 &h31 &h34...? 
    Friday, October 09, 2009 4:41 AM