打印本文 打印本文 关闭窗口 关闭窗口
用VB实现一个简单的ESMTP客户端
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2070  更新时间:2009/4/23 18:59:49  文章录入:mintao  责任编辑:mintao
;  i = 0
    out = ""
   
    While (i < len1)
  
        Do
            c1 = base64DecodeChars(Asc(Mid(str, i + 1, 1)) And 255)
            i = i + 1
        Loop While (i < len1 And c1 = -1)
        If (c1 = -1) Then
            base64decode = out
            Exit Function
        End If
  
        Do
            c2 = base64DecodeChars(Asc(Mid(str, i + 1, 1)) And 255)
            i = i + 1
        Loop While (i < len1 And c2 = -1)
        If (c2 = -1) Then
            base64decode = out
            Exit Function
        End If
        out = out + Chr((c1 * 4) Or ((c2 And 48) \ 16))

        Do
            c3 = base64DecodeChars(Asc(Mid(str, i + 1, 1)) And 255)
            i = i + 1
            If (c3 = 61) Then
                base64decode = out
                c3 = base64DecodeChars(c3)
            End If
        Loop While (i < len1 And c3 = -1)
        If (c3 = -1) Then
            base64decode = out
            Exit Function
        End If
        out = out + Chr(((c2 And 15) * 16) Or ((c3 And 60) \ 4))

        Do
            c4 = base64DecodeChars(Asc(Mid(str, i + 1, 1)) And 255)
            i = i + 1
            If (c4 = 61) Then
                base64decode = out
                c4 = base64DecodeChars(c4)
            End If
        Loop While (i < len1 And c4 = -1)
        If (c4 = -1) Then
            base64decode = out
            Exit Function
        End If

        out = out + Chr(((c3 And 3) * 64) Or c4)
    Wend
   
    base64decode = out
End Function

Function utf16to8(str As String) As String


    Dim out, i, len1, c
    out = ""
    len1 = Len(str)
    For i = 1 To len1
        c = Asc(Mid(str, i, 1))
        If ((c >= 1) And (c <= 127)) Then
            out = out + Mid(str, i, 1)
        ElseIf (c > 2047) Then
            out = out + Chr(224 Or ((c \ 4096) And 15))
            out = out + Chr(128 Or ((c \ 64) And 63))
            out = out + Chr(128 Or (c And 63))
        Else
            out = out + Chr(192 Or ((c \ 64) And 31))
            out = out + Chr(128 Or (c And 63))
        End If
    Next
    utf16to8 = out
End Function

Function utf8to16(str As String) As String


    Dim out, i, len1, c
    Dim char2, char3

    out = ""
    len1 = Len(str)
    i = 0
    While (i < len1)
        c = Asc(Mid(str, i + 1, 1))
        i = i + 1
        Select Case (c \ 16)
   
        Case 0 To 7
            out = out + Mid(str, i, 1)
       
        Case 12, 13
            char2 = Asc(Mid(str, i + 1, 1))
            i = i + 1
            out = out + Chr(((c And 31) * 64) Or (char2 And 31))
        Case 14
            char2 = Asc(Mid(str, i + 1, 1))
            i = i + 1
            char3 = Asc(Mid(str, i + 1, 1))
            i = i + 1
            out = out + Chr(((c And 15) * 4096) Or ((char2 And 63) * 64) Or ((char3 And 63)))
        End Select
    Wend

    utf8to16 = out
End Function

 

上一页  [1] [2] [3] 

打印本文 打印本文 关闭窗口 关闭窗口