HI,
Please look at following code example:
string convert2string(byte [] bys)
{
string string1 = Encoding.ASCII.GetString(bys, 0, 30).TrimEnd(null);
return string1;
}
byte [] allzero = new byte [40];
string dbstr = convert2string(byte);
After I get dbstr(which is empty), I write it to SQL database. When I read
this from database again, and serilize to XML message, I see
..... which means dbstr actually was not empty,
it filled with all "0" inside. Can anybody explain why? How can I get rid of
it? Thank you.
David 3 2272
"David Wang" <wg*****@yahoo.com> wrote in message
news:uO***************@TK2MSFTNGP09.phx.gbl... string convert2string(byte [] bys) { string string1 = Encoding.ASCII.GetString(bys, 0,
30).TrimEnd(null); return string1; }
byte [] allzero = new byte [40]; string dbstr = convert2string(byte);
TYPO: I think you mean convert2string(allzero) After I get dbstr(which is empty),
It is NOT empty... Just because it has non-printable characters
doesn't make it empty.
If you do:
Console.WriteLine("Length is: " + dbstr.Length);
You'll find it has 30 characters (I assume all are ASCII code 0).
byte [] allzero = new byte [40];
creates an array of value-types. So you have 40 bytes, each with a
default value of 0.
I suspect you'll want to add a check in convert2string to look for
all-zero case and return "" instead.
HTH,
Mike
David Wang <wg*****@yahoo.com> wrote: Please look at following code example: string convert2string(byte [] bys) { string string1 = Encoding.ASCII.GetString(bys, 0, 30).TrimEnd(null);
return string1; }
byte [] allzero = new byte [40]; string dbstr = convert2string(byte);
After I get dbstr(which is empty), I write it to SQL database. When I read this from database again, and serilize to XML message, I see ..... which means dbstr actually was not empty, it filled with all "0" inside. Can anybody explain why? How can I get rid of it? Thank you.
Instead of calling TrimEnd (null) which will do nothing, call
TrimEnd ('\0')
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
David Wang <wg*****@yahoo.com> wrote: Please look at following code example: string convert2string(byte [] bys) { string string1 = Encoding.ASCII.GetString(bys, 0, 30).TrimEnd(null);
return string1; }
byte [] allzero = new byte [40]; string dbstr = convert2string(byte);
After I get dbstr(which is empty), I write it to SQL database. When I read this from database again, and serilize to XML message, I see ..... which means dbstr actually was not empty, it filled with all "0" inside. Can anybody explain why? How can I get rid of it? Thank you.
Instead of calling TrimEnd (null) which will do nothing, call
TrimEnd ('\0')
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Dean |
last post by:
Hi
I have been reading quite a lot of Python source code recently and I have
come across a particular construct which I don't understand. I would be
grateful if somebody could explain the reason...
|
by: Chris |
last post by:
Hello
Could anyone explain why the following:
#footer ul
{
float : left;
margin : 2px 0px 7px 28px;
padding : 0px;
width : 360px;
|
by: C++fan |
last post by:
The following code is for list operation. But I can not understand.
Could anyone explain the code for me?
/*
* List definitions.
*/
#define LIST_HEAD(name, type)
struct name {
type...
|
by: Gactimus |
last post by:
Can anyone explain what the lines with the '*' by them do?
-----------
#ifndef _COUNTER_H
#define _COUNTER_H
#include <iostream>
using namespace std;
class Counter
|
by: Jeff Boes |
last post by:
I'm hoping there's someone here with experience in building the Visual
Explain tool from Red Hat. I downloaded it and the J2 SDK, but when I
attempt to follow the build instructions, I get messages...
|
by: Andrew |
last post by:
Hello, friends,
I am implementing web app security using asp.net 1.1, and I found the
following source code from Yahoo! Mail login page:
<form method="post"...
|
by: David |
last post by:
We've developed a seismic-data processing app in VB.NET 1.1 which runs on XP
Pro using SQL2K. Like all seismic data apps, it deals with HUGE amounts of
binary data (we use NTFS sparse "flat...
|
by: active |
last post by:
I tried to use the help on 'controls' to find out what it is used for but
there is so many different uses for the word as to make the help useless.
So I tried the following.
It appears the...
|
by: kardon33 |
last post by:
I have this bit of code and im not used to C and it would help if some one could explain it in lamence terms.
typedef struct {
uchar IP; // IP address
ushort Port; // UDP port BYTE-SWAPPED...
|
by: Chuthu |
last post by:
Could anyone explain me the following concepts in detail?
1. JAXP
2. BGRAPH
3. JBOSS work flow engine
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
| |