i have the following string "USB SERIAL PORT (COM6)" i want to get COM6 out of this.
This is the code i am trying to use
string.substring(3, string.length - 1)
something of that sort. Havent been able to get anything.
i have the following string "USB SERIAL PORT (COM6)" i want to get COM6 out of this.
This is the code i am trying to use
string.substring(3, string.length - 1)
something of that sort. Havent been able to get anything.
You'd be better off using the last occurrence of (
as an index, in case one day your string changes format, or com6 is longer (com10):
Dim lastBra as Integer = myString.LastIndexOf("("c)
Dim lastKet as Integer = myString.LastIndexOf(")"c)
Dim subs as String = myString.Substring(lastBra + 1, lastKet - lastBra - 1)
It's lastBra+1 because we want the character after the open bracket as a start. The length to substring is the bracket indexes, less one because we don't want the last bracket to be included: