您的位置:首页 > 其它

string to bytes的转化

2005-09-23 12:42 435 查看
    '**********************************************************************************************
    '** Procedure:      KeyToBytes
    '**
    '** Description:    Returns log file name including path based on config settings and date.
    '**********************************************************************************************
    Private Shared Function KeyToBytes(ByVal mstring As String) As Byte()

        Dim mchararray As Char()
        Dim result As Byte()
        Dim mbytearray As Byte()
        Dim i As Integer = 0
        Dim t As Integer = 0
        Dim m As Integer = 0
        Dim bytelength As Integer

        mchararray = mstring.ToCharArray()
        bytelength = BitConverter.GetBytes(mchararray(0)).Length()
        While (Not mchararray(m) = "")
            result = BitConverter.GetBytes(mchararray(m))
            For t = 0 To bytelength Step 1
                mbytearray(i) = result(t)
                i += 1
                If i > 16 Then
                    Exit While
                End If
            Next
            m += 1
        End While
        If i < 16 Then
            While (i <= 16)
                mbytearray(i) = 0
                i += 1
            End While
        End If
        Return mbytearray
    End Function
    '**********************************************************************************************
    '** Procedure:      MessageToBytes
    '**
    '** Description:    Returns log file name including path based on config settings and date.
    '**********************************************************************************************
    Private Shared Function MessageToBytes(ByVal mstring As String) As Byte()
        Dim mchararray As Char()
        Dim result As Byte()
        Dim mbytearray As Byte()
        Dim i As Integer = 0
        Dim t As Integer = 0
        Dim m As Integer = 0
        Dim bytelength As Integer
        mchararray = mstring.ToCharArray()
        bytelength = BitConverter.GetBytes(mchararray(0)).Length()
        While (Not mchararray(m) = "")
            result = BitConverter.GetBytes(mchararray(m))
            For t = 0 To bytelength Step 1
                mbytearray(i) = result(t)
                i += 1
                'If i > 16 Then
                'Exit While
                'End If
            Next
            m += 1
        End While
        'If i < 16 Then
        'While (i <= 16)
        'mbytearray(i) = 0
        'i += 1
        'End While
        'End If
        Return mbytearray
    End Function
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息