Private Function GetMAC() As String
Dim macAddresses As String = ""
For Each nic As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()
If nic.OperationalStatus = OperationalStatus.Up Then
macAddresses += nic.GetPhysicalAddress().ToString()
Exit For
End If
Next
Return macAddresses
End Function
Dim str As String = GetMAC()
MsgBox(str)
str值为F406697228D3 现在我想改变这个F4-06-69-72-28-D3 ..?
答案 0 :(得分:1)
您可以使用这样的简单For
循环执行此操作: -
Public Function GetFormattedString(input As String) As String
Dim result As String = String.Empty
For index = 0 To input.Length Step +2
result += input.Substring(index, Math.Min(2, input.Length - index)) + "-"
Next
Return result.Trim("-")
End Function
Working Fiddle供您参考。