How to show non printable characters in a listbox

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.
cmdolcetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kaufmed   ( ⚆ _ ⚆ )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 EngineerCommented:
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
cmdolcetAuthor 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.
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

cmdolcetAuthor 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
kaufmed   ( ⚆ _ ⚆ )Commented:
I don't believe ListBox supports carriage return/newline in its display. Is this WinForms or WPF?
cmdolcetAuthor Commented:
This is a WindForm. How can I convert the non printable to something readable?
kaufmed   ( ⚆ _ ⚆ )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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.