PC Review


Reply
Thread Tools Rate Thread

Byte[] to string - Kinda...

 
 
=?Utf-8?B?anVzb3Zza3lAYW5vdGhlcnJldGFyZGVkLmNvbQ==
Guest
Posts: n/a
 
      11th May 2004
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 .GetBinaryContent() 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.Encoding.[EVERYTHING!].GetString([byte array]) with no luck. Any suggestions? Thanks in advance

Josh Usovsky
 
Reply With Quote
 
 
 
 
Tian Min Huang
Guest
Posts: n/a
 
      12th May 2004
Hello Josh,

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

ASCIIEncoding.GetString Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemtextasciiencodingclassgetstringtopic.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.

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      14th May 2004
(E-Mail Removed) <(E-Mail Removed)> wrote:
> 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.


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.FromBase64String 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.GetString to make - again, with whatever
encoding was originally used for that step.)

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
=?Utf-8?B?anVzb3Zza3lAYW5vdGhlcnJldGFyZGVkLmNvbQ==
Guest
Posts: n/a
 
      17th May 2004
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 getBinaryContent() 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
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      17th May 2004
(E-Mail Removed) <(E-Mail Removed)> wrote:
> 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 getBinaryContent() 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.


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

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Tian Min Huang
Guest
Posts: n/a
 
      18th May 2004
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting from byte to string and back to byte ends in different results? mfunkmann@yahoo.com Microsoft C# .NET 1 17th Dec 2006 02:53 PM
How to convert byte() to string, and from string back to byte() moondaddy Microsoft VB .NET 4 15th Aug 2005 03:25 PM
Problem converting byte() to string and then back to byte() moondaddy Microsoft VB .NET 8 3rd May 2005 07:23 AM
string >> byte array >> string representation >> byte array >> string !! David Bargna Microsoft VB .NET 4 6th Oct 2003 04:02 PM
Kinda Funny Windows Bug my 6 byte documents show up as 1KB in explorer view (see screenshot) Christian Blackburn Microsoft VB .NET 7 15th Sep 2003 02:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 PM.