How to show non printable characters in a listbox

cmdolcet
cmdolcet used Ask the Experts™
on
I am capturing a string of data that has some no printable characters from a COM bus. I capture them with a string variable and then display them inside my listbox window.

I put breakpoints on the string variable after a capture the complete data from the COM bus and I see the non-printables in the watch window. However I don't see the non printable inside the listbox control.

Any ideas would be appreciated

Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
However I don't see the non printable inside the listbox control.
There is a reason they are called "non-printable" characters. "Printable" in this context does not mean that they won't go to a printer; it means that they won't be visible anywhere. If you want to see them, then you need to come up with your own visualization system, similar to what Notepad++ does.

Screenshot
Miguel OzSenior Software Engineer
Top Expert 2009

Commented:
It depends what are you trying to capture as information. In the past I used to convert the incoming string to an hexadecimal string
var hexString = string.Join("", input.Select(c => ((int)c).ToString("X2")));

Open in new window

then you can view both strings side to side if needed but I only needed the hex string to play back messages for testing.

If you need to convert from and to hex see FrancSpike  code in this link

Author

Commented:
Miguel,

I am trying to capture the received value and its CRLF at the end of the message packet.

I capture the value just fine, but the CRLF is what I am having an issue with.

So I dont need to convert anything I just need it to appear in the listbox.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Author

Commented:
Miguel and Kaufmed,

I guess a screen shot would be better explained. Please see the attached file. What I would like to do is translate this non-printable (CR) to a {CR} in the window.
Capture.png
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
I don't believe ListBox supports carriage return/newline in its display. Is this WinForms or WPF?

Author

Commented:
This is a WindForm. How can I convert the non printable to something readable?
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
It should be as simple as a replace if you want a straight textual representation:

string updated = source.Replace("\r", "{\\r}")
                       .Replace("\n", "{\\n}");

Open in new window


If you want something fancier, like what I showed in my N++ screenshot, then you'd have to draw your own control, which is much more complex.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial