473,322 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 .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
Jul 21 '05 #1
5 1714
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.as p

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.

Jul 21 '05 #2
ju******@anotherretarded.com <ju******@anotherretarded.com> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3
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
Jul 21 '05 #4
ju******@anotherretarded.com <ju******@anotherretarded.com> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5
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.

Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Vince | last post by:
Hi, I have replaced my BYTE* by a vector<BYTE> and before I used to do : void CCardRecord::GetRecData(int nOffset, int nDataSize, CString& csValue) { BYTE *pTmp = NULL; pTmp = new BYTE;...
3
by: Ken Durden | last post by:
Is there any constant in the .NET API Framework indicating the # of bits per byte (or int, or anything else)? Kinda like std::numeric_limits for C#? I know they're all constant (unlike C/C++) I...
4
by: Hans Nieser | last post by:
Hi, I'm pretty new to C#, and recently I have been experimenting with sockets. However, I can't find a nice way (I've been fiddling with for-loops to no avail) to parse the data that comes in...
15
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
7
by: Christian Blackburn | last post by:
Hi Gang, I just thought you might all get a kick out of this enormous rounding bug in Windows Explorer (Win2K Pro Sp4). You see my 6 byte document is listed as 1KB instead of 0KB which is what it...
8
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
5
by: jusovsky | last post by:
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...
5
by: jeremyje | last post by:
I'm writing some code that will convert a regular string to a byte for compression and then beable to convert that compressed string back into original form. Conceptually I have.... For...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.