我从返回功能中得到这样的值,现在我想要字符串

时间:2015-08-05 07:23:08

标签: asp.net vb.net

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 ..?

1 个答案:

答案 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供您参考。