'  VB.Net 把byte array轉成String
        Dim b As Byte() = {65, 66, 67, 68, 69, 70, 71}
        Dim str As String
        Dim enc As New System.Text.ASCIIEncoding()
        Response.Write(enc.GetString(b))

        '   VB.Net 把String 轉成byte array
        Dim encAs New System.Text.ASCIIEncoding()
        Dim b As Byte() = enc.GetBytes("ABCDEFG")
        For i As Integer = 0 To b.Length - 1
                Response.Write(b(i).ToString()+",")
        Next

        ' 將字串轉成byte陣列
        Shared Function StrToByteArray(ByVal str As String) As Byte()
            Dim encoding As New System.Text.ASCIIEncoding()
            Return encoding.GetBytes(str)
        End Function

        ' 將byte陣列轉成字串
        Shared Function ByteArrayToStr(ByVal bt As Byte()) As String
            Dim encoding As New System.Text.ASCIIEncoding()
            Return encoding.GetString(bt)
        End Function

文章標籤
全站熱搜
創作者介紹
創作者 湯瑪的吳 的頭像
湯瑪的吳

安達利機車行

湯瑪的吳 發表在 痞客邦 留言(2) 人氣(796)