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

dengwei007 2003-12-20 06:31:18
把类似于这种“%B2%BB%B4%ED%A3%AC%D6%A7%B3%D6%A1%A3”代码转换为普通字符。
...全文
71 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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”转换过来就是“不错,支持。”


7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧