[英]Im get the value like this from a return fuction now i want the string like
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 ..?
您可以使用以下简单的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
工作小提琴供您参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.