Trace class truncates string when it contains null chars???

B

Bob Rock

Hello,

using the WriteLine method of the Trace class I noticed that strings
containing null characters (i.e. \0) get truncated in the output window at
the first null char and anything that follows simply gets lost. I'm using
..NET 1.1 (have not tested with 2.0).

Try the following to see what I mean:

Trace.WriteLine("xxxx\0\0xxxx");

Is there a way to avoid this behavior???



Regards,
Bob Rock
 
B

Ben Voigt

Bob Rock said:
Hello,

using the WriteLine method of the Trace class I noticed that strings
containing null characters (i.e. \0) get truncated in the output window at
the first null char and anything that follows simply gets lost. I'm using
.NET 1.1 (have not tested with 2.0).

Try the following to see what I mean:

Trace.WriteLine("xxxx\0\0xxxx");

Is there a way to avoid this behavior???

I believe that's because the actual protocol used to send strings to the
debugger uses standard C strings (NUL-terminated). Tracing into a logfile,
for example, wouldn't have that problem.

You may want to scan your string for control characters and convert them to
escape sequences, so that you would get @"xxxx\0\0xxxx" with the characters
\0 actually appearing, in case you need to know about the presence of the
control characters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top