0
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 values comes as F406697228D3 now i want change this as F4-06-69-72-28-D3..?

Rahul Singh
  • 21,585
  • 6
  • 41
  • 56
Asif Ganaie
  • 101
  • 9

1 Answers1

1

You can do this with a simple For loop like this:-

 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 for your reference.

Rahul Singh
  • 21,585
  • 6
  • 41
  • 56