473,396 Members | 1,671 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,396 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 1718
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.