之前有问如何实现 UNICODE编码见
http://topic.csdn.net/u/20090331/14/e849fef1-cd72-4941-8ae2-98b8fabff299.html
Public Function URLEncode(ByRef strURL As String) As String
Dim I As Long
Dim tempStr As String
For I = 1 To Len(strURL)
If Asc(Mid(strURL, I, 1)) < 0 Then
tempStr = "%" & Right(CStr(Hex(Asc(Mid(strURL, I, 1)))), 2)
tempStr = "%" & Left(CStr(Hex(Asc(Mid(strURL, I, 1)))), Len(CStr(Hex(Asc(Mid(strURL, I, 1))))) - 2) & tempStr
URLEncode = URLEncode & tempStr
ElseIf (Asc(Mid(strURL, I, 1)) >= 65 And Asc(Mid(strURL, I, 1)) <= 90) Or (Asc(Mid(strURL, I, 1)) >= 97 And Asc(Mid(strURL, I, 1)) <= 122) Then
URLEncode = URLEncode & Mid(strURL, I, 1)
Else
URLEncode = URLEncode & "%" & Hex(Asc(Mid(strURL, I, 1)))
End If
Next
End Function
可实现但是反 UNICODE编码
Public Function URLDecode(ByRef strURL As String) As String
Dim I As LongIf InStr(strURL, "%") = 0 Then URLDecode = strURL: Exit FunctionFor I = 1 To Len(strURL)
If Mid(strURL, I, 1) = "%" Then
If Val("&H" & Mid(strURL, I + 1, 2)) > 127 Then
URLDecode = URLDecode & Chr(Val("&H" & Mid(strURL, I + 1, 2) & Mid(strURL, I + 4, 2)))
I = I + 5
Else
URLDecode = URLDecode & Chr(Val("&H" & Mid(strURL, I + 1, 2)))
I = I + 2
End If
Else
URLDecode = URLDecode & Mid(strURL, I, 1)
End If
Next
End Function
好像有问题比如你好的 UNICODE 为 %E4%BD%A0%E5%A5%BD但是这个函数 后的结果是什么 涴 什么 乱码的该如何解决这个问题?
http://topic.csdn.net/u/20090331/14/e849fef1-cd72-4941-8ae2-98b8fabff299.html
Public Function URLEncode(ByRef strURL As String) As String
Dim I As Long
Dim tempStr As String
For I = 1 To Len(strURL)
If Asc(Mid(strURL, I, 1)) < 0 Then
tempStr = "%" & Right(CStr(Hex(Asc(Mid(strURL, I, 1)))), 2)
tempStr = "%" & Left(CStr(Hex(Asc(Mid(strURL, I, 1)))), Len(CStr(Hex(Asc(Mid(strURL, I, 1))))) - 2) & tempStr
URLEncode = URLEncode & tempStr
ElseIf (Asc(Mid(strURL, I, 1)) >= 65 And Asc(Mid(strURL, I, 1)) <= 90) Or (Asc(Mid(strURL, I, 1)) >= 97 And Asc(Mid(strURL, I, 1)) <= 122) Then
URLEncode = URLEncode & Mid(strURL, I, 1)
Else
URLEncode = URLEncode & "%" & Hex(Asc(Mid(strURL, I, 1)))
End If
Next
End Function
可实现但是反 UNICODE编码
Public Function URLDecode(ByRef strURL As String) As String
Dim I As LongIf InStr(strURL, "%") = 0 Then URLDecode = strURL: Exit FunctionFor I = 1 To Len(strURL)
If Mid(strURL, I, 1) = "%" Then
If Val("&H" & Mid(strURL, I + 1, 2)) > 127 Then
URLDecode = URLDecode & Chr(Val("&H" & Mid(strURL, I + 1, 2) & Mid(strURL, I + 4, 2)))
I = I + 5
Else
URLDecode = URLDecode & Chr(Val("&H" & Mid(strURL, I + 1, 2)))
I = I + 2
End If
Else
URLDecode = URLDecode & Mid(strURL, I, 1)
End If
Next
End Function
好像有问题比如你好的 UNICODE 为 %E4%BD%A0%E5%A5%BD但是这个函数 后的结果是什么 涴 什么 乱码的该如何解决这个问题?
解决方案 »
- 哪有NET版式网上考试系统下载
- ActiveReports问题
- 我急需一分一万字的社会调查,有位兄弟帮下忙啊!
- 有谁知道这会是什么错误?
- vba 如何编写?
- 把流氓恶棍从CSDN踢出去!
- 请问如何在MsAgent角色的气球提示中使用按钮等对象?
- 當我用datagrid控件顯示SQL數据庫一個表的一百万條記錄時.非常慢.有沒有辦法解結.是不是不能解結.
- 怎样在一个表单的Frame控件上自动增加和删除text控件。
- 请问Witch_Subrina(*^.^*躺在太阳下睡觉!)和大家,谁有http://www.anfyteam.com/这个东东的注册码?
- Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)服务器如何只向这个客户端发送数据呢?而不是广播式的发信息
- vb 怎样判断一个字符串是不是有效的时间
2、编码不是Unicode,编码是GBK的HEX形式。
3、造成你编码程序错误的原因是Integer类型的符号位问题。
Private Sub Form_Load()
Dim tByte() As Byte
Debug.Print DeCode("%D0%A1%CF%C9%C3%C3%CA%C7%B8%F6%BA%C3%BA%A2%D7%D3")
End SubPublic Function EnCode(ByVal pString As String) As String
'编码函数 Dim tOutString As String
Dim tSurBytes() As Byte
Dim tSurBytes_Len As Long
Dim tSurBytes_Index As Long
Dim tDesStrs() As String
Dim tDesStrs_Len As Long
Dim tDesStrs_Index As Long
tSurBytes() = StrConv(pString, vbFromUnicode)
tSurBytes_Len = UBound(tSurBytes())
tDesStrs_Len = tSurBytes_Len + 1
ReDim tDesStrs(tDesStrs_Len)
For tSurBytes_Index = 0 To tSurBytes_Len
tDesStrs_Index = tSurBytes_Index + 1
tDesStrs(tDesStrs_Index) = Hex(tSurBytes(tSurBytes_Index))
Next
tOutString = Join(tDesStrs(), "%")
EnCode = tOutString
End FunctionPublic Function DeCode(ByVal pString As String) As String
'解码函数
Dim tOutString As String
Dim tSurStrs() As String
Dim tSurStrs_Len As Long
Dim tSurStrs_Index As Long
Dim tDesBytes() As Byte
Dim tDesBytes_Len As Long
Dim tDesBytes_Index As Long
tSurStrs() = Split(pString, "%")
tSurStrs_Len = UBound(tSurStrs())
tDesBytes_Len = tSurStrs_Len - 1
ReDim tDesBytes(tDesBytes_Len)
For tDesBytes_Index = 0 To tDesBytes_Len
tSurStrs_Index = tDesBytes_Index + 1
tDesBytes(tDesBytes_Index) = CByte("&H" & tSurStrs(tSurStrs_Index))
Next
tOutString = StrConv(tDesBytes(), vbUnicode)
DeCode = tOutString
End Function
http://www.google.cn/
输入汉字看看所以好像并不是我想要的
我是参照你在这个帖子里说的百度的编码做的。
http://topic.csdn.net/u/20090331/14/e849fef1-cd72-4941-8ae2-98b8fabff299.html百度是GB2312编码,Google是UTF8编码。UTF8做起来就麻烦多了,可不是你想象中那么简单的。
2、做如下转换:U-00000000 - U-0000007F: 0xxxxxxx
U-00000080 - U-000007FF: 110xxxxx 10xxxxxx
U-00000800 - U-0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx
U-00010000 - U-001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
U-00200000 - U-03FFFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
U-04000000 - U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx这是Linux下那帮王八蛋搞出来的操蛋规则,只能用状态机来解读,不能直接线性转换。
GB2312那GG 的是不是没办法反编码了?
可以互相转换,但解码程序复杂多了。我有闲功夫的话倒是可以写出来,不过那代码你看起来会晕的。汉字编码基本是这样:
1110xxxx 10xxxxxx 10xxxxx那么解码程序是这样的:1、三个为一组。
2、取第一个输入编码的末4位:OBH = InByte1 and &HF
3、作为输出编码第一个的高4位:OutByte1 = OBH * &H10
4、取第二个输入编码的5-2位:OBL = (InByte2 And &H3C) \ &H10
3、作为输出编码第一个的低4位:OutByte1 = OutByte + OBL
5、取第二个输入编码的1-0位:OBH = (InByte2 And &H3)
6、作为输出编码第二个的高2位:OutByte2 = OBH * &H40
7、取第三个输入编码的低6位:OBL = (InByte3 And &H3F)
8、作为输出编码第二个的低6位:OutByte2 = OutByte2 + OBL
9、接下来是把字节变成字符串……现在你应该知道UTF8是多么讨厌一种编码了吧?
原来BAIDU 里 输入"你好" 转化后为 "%C4%E3%BA%C3"Private Function URLDecode(ByRef strURL As String) As String
Dim i As LongIf InStr(strURL, "%") = 0 Then URLDecode = strURL: Exit FunctionFor i = 1 To Len(strURL)
If Mid(strURL, i, 1) = "%" Then
If Val("&H" & Mid(strURL, i + 1, 2)) > 127 Then
URLDecode = URLDecode & Chr(Val("&H" & Mid(strURL, i + 1, 2) & Mid(strURL, i + 4, 2)))
i = i + 5
Else
URLDecode = URLDecode & Chr(Val("&H" & Mid(strURL, i + 1, 2)))
i = i + 2
End If
Else
URLDecode = URLDecode & Mid(strURL, i, 1)
End If
Next
End Function
这个代码是有效果的关键是 google 里
输入"你好" 转化后为 %E4%BD%A0%E5%A5%BD"要反编码有难度啊