【问题标题】:Im get the value like this from a return fuction now i want the string like我从返回函数中得到这样的值现在我想要这样的字符串
【发布时间】:2015-10-27 20:10:51
【问题描述】:
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..?

【问题讨论】:

标签: asp.net vb.net


【解决方案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供您参考。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多