Hello,
How to uniquely differentiate two similar substrings in a string (Shell.Result)? I tried several approaches, but all my attempts failed because it systematically detects “Hardware Port: Ethernet” in “Hardware Port: Ethernet Adapter”!
Var sh As New Shell
sh.Execute("/usr/sbin/networksetup -listallhardwareports")
if sh.IsRunning Then
sh.Poll
end if
Dim inputString As String = sh.Result
Dim pattern As String = "\bHardware Port: Ethernet\b"
Dim regex As New RegEx
regex.SearchPattern = pattern
Dim match As RegExMatch
match = regex.Search(inputString)
If sh.ErrorCode = 0 Then
If match <> Nil Then
MsgBox "An Ethernet port is present""
Else
MsgBox "No Ethernet port is present!”
End If
End If
Thanks.
4 posts - 2 participants