String from a byte array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Dann

    String from a byte array

    Just wondering about the best way of assembling a string from a byte
    array in VB.Net. I have a sequence of Ascii characters read into a
    byte array from a binary file and need to reassemble these into their
    original string.

    I guess I could do something like:

    for i as integer = 0 to ubound(byte())
    string &= byte(i) (do I need a .tostring)
    next

    But maybe there's a more direct/approved/elegant method?

    If it makes any difference, in this particular example, it's a
    relatively short (16 byte string) that will probably only be used once
    in the program so there's no great need for efficiency. But I'm asking
    more out of interest in the principle as to the best approach.

    TIA
    John Dann
  • Cor Ligthert

    #2
    Re: String from a byte array

    Hi John,

    Have a look at this page, (what you ask is in the bottom)



    However keep in mind that ASCII is 7 bits, so maybe are you looking for
    another format, however that is as well in the encode pages so see what you
    need for that now you have this link.

    I hope this helps?

    Cor


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: String from a byte array

      * John Dann <news@prodata.c o.uk> scripsit:[color=blue]
      > Just wondering about the best way of assembling a string from a byte
      > array in VB.Net. I have a sequence of Ascii characters read into a
      > byte array from a binary file and need to reassemble these into their
      > original string.[/color]

      \\\
      Dim s As String = System.Text.Enc oding.ASCII.Get String(abyt)
      ///

      For other encodings, play around with the 'ASCII', there are many other
      encodings available too.

      --
      Herfried K. Wagner [MVP]
      <URL:http://dotnet.mvps.org/>

      Comment

      Working...