求代码转换函数(在线等)

dengwei007 2003-12-20 06:31:18
把类似于这种“%B2%BB%B4%ED%A3%AC%D6%A7%B3%D6%A1%A3”代码转换为普通字符。
...全文
12 点赞 收藏 8
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
dengwei007 2004-01-03
northwolves(野性的呼唤)的方法有不少缺陷。
回复
liyan010 2003-12-21
up
回复
rainstormmaster 2003-12-21
不要忘了:url编码除了有“%”之外还有“+”,如这样的字串:

%d6%a7%b3%d6+vb+%d1%a7%ba%c3%b2%bb

因此,对“+”也要进行处理
回复
seraph2 2003-12-21
进制转换,循环处理,高,比我高多了,我从来都没想过,虽然做了不少程序,但是-----
佩服,有空聊聊,因为对进制转换一类的程序我做的还是太少了!
回复
northwolves 2003-12-21

Private Sub Form_Load()
x = "%B2%BB%B4%ED%A3%AC%D6%A7%B3%D6%A1%A3"
MsgBox decode(x)
End Sub
Function decode(ByVal x As String) As String
'x = "%B2%BB%B4%ED%A3%AC%D6%A7%B3%D6%A1%A3"
Dim temp
Dim i As Long
temp = Split(x, "%")
For i = 1 To UBound(temp) Step 2
decode = decode & Chr("&H" & temp(i) & temp(i + 1))
Next

End Function
回复
rainstormmaster 2003-12-20
Option Explicit

Public Function UrlDecode(ByVal sEncoded As String) As String
'========================================================
' Accept url-encoded string
' Return decoded string
'========================================================
Dim pos As Long ' position of InStr target
Dim i As Integer, lastpos As Integer, flag As Boolean
Dim temp As String, outstr As String
If sEncoded = "" Then Exit Function
' convert "+" to space
pos = 0
Do
pos = InStr(pos + 1, sEncoded, "+")
If pos = 0 Then Exit Do
Mid$(sEncoded, pos, 1) = " "
Loop

' convert "%xx%xx" to chinese character
pos = 0

On Error Resume Next

i = 0
Do
pos = InStr(pos + 1, sEncoded, "%")
If pos = 0 Then
If lastpos <> 0 Then
outstr = outstr & Mid(sEncoded, lastpos + 3)
End If
Exit Do
End If
lastpos = pos
If flag = False Then
outstr = Left$(sEncoded, pos - 1)
flag = True
End If
temp = temp & Mid$(sEncoded, pos + 1, 2)
i = i + 1
If i Mod 2 = 0 Then
outstr = outstr & Chr$("&H" & temp)
temp = ""
End If
Loop

On Error GoTo 0 'reset error handling
If flag = True Then
UrlDecode = outstr
Else
UrlDecode = sEncoded
End If

End Function

Private Sub Command1_Click()
Dim s As String
s = "%B2%BB%B4%ED%A3%AC%D6%A7%B3%D6%A1%A3"
s = UrlDecode(s)
Debug.Print s

End Sub
回复
dengwei007 2003-12-20
谢谢,如果没有问题了就给你100分。
回复
胖河马 2003-12-20
%B2%BB相当于Chr(&HB2BB)

“%B2%BB%B4%ED%A3%AC%D6%A7%B3%D6%A1%A3”转换过来就是“不错,支持。”


回复
发动态
发帖子
VB基础类
创建于2007-09-28

7451

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告