2020年5月15日 星期五

vb.net Binary 轉 String [Binary to String]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    Public Function BinaryToString(ByVal Binary As String) As String

        Dim Characters As String = System.Text.RegularExpressions.Regex.Replace(Binary, "[^01]", "")

        Dim ByteArray((Characters.Length / 8) - 1) As Byte

        For Index As Integer = 0 To ByteArray.Length - 1

            ByteArray(Index) = Convert.ToByte(Characters.Substring(Index * 8, 8), 2)

        Next

        Return System.Text.ASCIIEncoding.ASCII.GetString(ByteArray)

    End Function

沒有留言:

張貼留言