Hi all. I'm using this seemingly simple code (from msdn) to fill a combobox with available Com ports but it keeps adding this strange character at the end of it, like so "COM4洐"

It was working fine yesterday, but it started doing it after a reboot and no change to the code.

foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
            Combobox1.Items.Add(s);

I ran this program by not using a combo box but a command line. And it works fine for me. The code I used:

public void serialport()
        {
            foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
            {

                Console.WriteLine("{0}", s);
            
            }
                       
        }

Sometimes people get this strange character, when they use textfiles, because of null or next line character.Are you using textfiles at some point?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.