VB中当charset=UTF-8时base64解码算法,请各位大侠多多指点
VB中当charset=UTF-8时base64解码算法,请各位大侠多多指点 http://wenku.baidu.com/view/91e227717fd5360cba1adb41.html http://download.csdn.net/download/leer168/647602
Private Function funUTF8ToUniCode(ByRef bytUTF8() As Byte) As String
Dim utfLen As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim N As Long
Dim B As Byte
Dim cnt As Byte
Dim Buf() As String
utfLen = -1
On Error GoTo errFun
funUTF8ToUniCode = ""
utfLen = UBound(bytUTF8)
If utfLen = -1 Then Exit Function
ReDim Buf(utfLen)
i = 0
j = 0
Do While i <= utfLen
B = bytUTF8(i)
If (B And &HFC) = &HFC Then
cnt = 6
ElseIf (B And &HF8) = &HF8 Then
cnt = 5
ElseIf (B And &HF0) = &HF0 Then
cnt = 4
ElseIf (B And &HE0) = &HE0 Then
cnt = 3
ElseIf (B And &HC0) = &HC0 Then
cnt = 2
Else
cnt = 1
End If
If i + cnt - 1 > utfLen Then
Buf(j) = "?"
Exit Do
End If
Select Case cnt
Case 2
N = B And &H1F
Case 3
N = B And &HF
Case 4
N = B And &H7
Case 5
N = B And &H3
Case 6
N = B And &H1
Case Else
Buf(j) = Chr(B)
GoTo Continued:
End Select
For k = 1 To cnt - 1
B = bytUTF8(i + k)
N = N * &H40 + (B And &H3F)
Next
Buf(j) = ChrW(N)
Continued:
i = i + cnt
j = j + 1
Loop
funUTF8ToUniCode = Join(Buf, "")
errFun:
End Function
先用这个函数可以把UTF8转换为UniCode。
然后再解码 第二个好像只针对gb2312时base64的解码,请问有没有utf-8时的base64解码,谢谢~! 其实你搞清楚了原理,怎么搞都无所谓的。 我自己弄了个,但是只能还原少量的,如果是大批量的,就会有错误,所以想参考下前辈们的精髓,以来提高自己的见识 编码,解码最伤脑筋,看的人眼睛发花。呵呵 但这也没办法,那玩意也只能糊弄下不懂的人,哎~!可怜的我啊,
我还得找找看有没有前辈们留下来的精髓。 你快成功了:) 谢谢,非常感谢你这几次的回帖
最精髓的是去看 PHP 的开源代码,里面有编码和解码函数源代码,当然还有别的值得看的东西
补充:VB , API