Results 1 to 6 of 6

Thread: [RESOLVED] convert object byte array to string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    102

    Resolved [RESOLVED] convert object byte array to string

    is there a quick command for this object to string?
    Code:
        Dim data As Object, datastr As String
            DnsSocketListener.GetData(data)
            datastr =

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: convert object byte array to string

    It depends exactly what the Byte array represents and what the text is supposed to represent. For instance, the code you would use to convert image data to a base-64 string and the code you would use to convert Unicode bytes to their equivalent text would be quite different. Please provide a FULL and CLEAR explanation of the problem rather than providing as little information as you can get away with.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    102

    Re: convert object byte array to string

    to be clear the byte array represents data form the server i connected to so i would think it would be ascii data but right now the data is a object byte array and needs to be a ascii stream

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: convert object byte array to string

    Quote Originally Posted by newbiedoobie1983 View Post
    the byte array represents data form the server i connected to
    That's a meaningless statement. You're basically saying "the data is the data". If you know what that data is, e.g. an image or some text, then tell us. If you don't know what it is then surely you need to find out, because how can you use it otherwise?

    Quote Originally Posted by newbiedoobie1983 View Post
    i would think it would be ascii data
    Why would you think that? Do you have a reason to think that? Do you think that because it's actually true? If so then why muddy the waters instead of just saying "it represents ASCII text"? If not then why aren't you finding out?

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: convert object byte array to string

    Even if you know that it should be some readable text, that doesn't mean that it has to be ASCII. There was a time when you could pretty much count on readable text being ASCII, but that time is in the past. If you don't know whether or not it is ASCII, you could wing it and hope for the best, but that's not necessarily the best solution. This would be the way to wing it:

    System.Text.Encoding.ASCII.GetString(data)

    If that results in what you expect, then you may have ASCII. If it results in garbage, then maybe not.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    102

    Re: convert object byte array to string

    Ok I do apolagize for being a newb ....... Ok most of the data recieved is text To be Honest I thought when i said ascii thats what it meant but as shaggy said some of the data is not legible text so i just simply said ascii due to that reason but that code works well for my situation shaggy thx you and also i thx jch for commenting does anyone know how to give props or credits on this site to solver? before i mark it as solved i wanna props but it is solved nm i got it i proped you both for helping

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width