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

  • Thread starter Thread starter Bob Rock
  • Start date Start date
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
 
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.
 
Back
Top