How to take part of string from Combobox?

My combobox has list in the form of "COM9 – XXXXXX XXXX".

I wish to take just the "COM9" so I can use it to connect to the serialport. How may this be done?

>Solution :

you can Split() the first space-character – no RegEx required

string result = "COM9 - XXXXXX XXXX".Split().First();

Leave a Reply