Trim not working on null characters

If you just want to remove all null characters from a string, try this:

debug = debug.Replace("\0", string.Empty);

If you only want to remove them from the ends of the string:

debug = debug.Trim('\0');

There's nothing special about null characters, but they aren't considered white space.


String.Trim() just doesn't consider the NUL character (\0) to be whitespace. Ultimately, it calls this function to determine whitespace, which doesn't treat it as such.

Frankly, I think that makes sense. Typically \0 is not whitespace.