Byte[] to string - Kinda...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jusovsky@anotherretarded.com

    #1

    Byte[] to string - Kinda...

    Hi guys. I'm parsing an XML document with the Chilkat XML.net parser. I am trying to take the easy way out since I'd rather not have to write my own. The problem is that the Chilkat parser automatically performs a whitespace trim on a node's content when it returns the value with the .Content property. To get around this, I have tried using the .GetBinaryConte nt() to just give me everything. The problem I am having is that the method returns a byte array, and I am having trouble getting the string back out of this. I've tried System.Text.Enc oding.[EVERYTHING!].GetString([byte array]) with no luck. Any suggestions? Thanks in advance

    Josh Usovsky
  • Tian Min Huang

    #2
    RE: Byte[] to string - Kinda...

    Hello Josh,

    Thanks for your post. As I understand, you want to convert Byte arrary to
    string. I suggest that you can check ASCIIEncoding.G etString method, please
    refer to the following MSDN article:

    ASCIIEncoding.G etString Method
    http://msdn.microsoft.com/library/de...us/cpref/html/
    frlrfsystemtext asciiencodingcl assgetstringtop ic.asp

    Hope this helps.

    Regards,

    HuangTM
    Microsoft Online Partner Support
    MCSE/MCSD

    Get Secure! -- www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.

    Comment

    • Jon Skeet [C# MVP]

      #3
      RE: Byte[] to string - Kinda...

      jusovsky@anothe rretarded.com <jusovsky@anoth erretarded.com> wrote:[color=blue]
      > Hi Tim, thanks for the follow up. I found that the content of the XML
      > node was being returned as a base-64 byte array. I?m not quite surte
      > of how to go about getting this back into an ascii string.[/color]

      What *exactly* do you mean by "a base-64 byte array"? Base64 is a text
      encoding of binary, so if something is base64 encoded the result should
      be text, rather than a byte array. Do you mean that it's gone something
      like:

      Binary data (byte[])
      to
      Base 64 encoding (string)
      to
      Binary data (byte[]) via a normal encoding

      ?

      If so, use the appropriate encoding to get back to the Base64 version,
      and then Convert.FromBas e64String to get the original binary. (If the
      original binary was itself an encoded form of a text string, you've got
      one more call to Encoding.GetStr ing to make - again, with whatever
      encoding was originally used for that step.)

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • jusovsky@anotherretarded.com

        #4
        RE: Byte[] to string - Kinda...

        Thank you for the reply, Jon. The original data is just ASCII text from an xml file. The parser that I am using automatically trims white space from the node content. I need the white space, however, so I am using the parser object's getBinaryConten t() method to return the content in binary form. It is *expecting* the content of the node to be base64-encoded in the file, and returns a byte[] containing the content. I have tried several converts and I still am not able to get back to the original string

        Josh

        Comment

        • Jon Skeet [C# MVP]

          #5
          RE: Byte[] to string - Kinda...

          jusovsky@anothe rretarded.com <jusovsky@anoth erretarded.com> wrote:[color=blue]
          > Thank you for the reply, Jon. The original data is just ASCII text
          > from an xml file. The parser that I am using automatically trims
          > white space from the node content. I need the white space, however,
          > so I am using the parser object's getBinaryConten t() method to return
          > the content in binary form. It is *expecting* the content of the node
          > to be base64-encoded in the file, and returns a byte[] containing the
          > content. I have tried several converts and I still am notable to get
          > back to the original string.[/color]

          It sounds like you're basically trying to use the
          getBinaryConten tMethod in the wrong situation then. Why are you using
          this particular parser?

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          • Tian Min Huang

            #6
            RE: Byte[] to string - Kinda...

            Hi Josh,

            Could you post some code snippet which is able to demonstrate the problem?

            Regards,

            HuangTM
            Microsoft Online Partner Support
            MCSE/MCSD

            Get Secure! -- www.microsoft.com/security
            This posting is provided "as is" with no warranties and confers no rights.

            Comment

            Working...