'看看我写的 URL 编码和解码程序
Public Function EncodeString(StringX As String) As String
Dim i As Long
Dim j As Long
Dim sByte() As Byte
For i = 0 To VBA.Len(VBA.Trim(StringX)) - 1
If (VBA.Asc(VBA.Mid(StringX, i + 1, 1)) >= VBA.Asc("0") And VBA.Asc(VBA.Mid(StringX, i + 1, 1)) <= VBA.Asc("9")) Or (VBA.Asc(VBA.Mid(StringX, i + 1, 1)) >= VBA.Asc("@") And VBA.Asc(VBA.Mid(StringX, i + 1, 1)) <= VBA.Asc("Z")) Or (Asc(VBA.Mid(StringX, i + 1, 1)) >= VBA.Asc("a") And VBA.Asc(VBA.Mid(StringX, i + 1, 1)) <= VBA.Asc("z")) Then
EncodeString = EncodeString & VBA.Mid(StringX, i + 1, 1)
Else
sByte = VBA.StrConv(VBA.Mid(StringX, i + 1, 1), vbFromUnicode)
For j = LBound(sByte) To UBound(sByte)
EncodeString = EncodeString & "%" & VBA.Hex(sByte(j))
Next j
End If
Next i
End Function
Public Function DecodeString(StringX As String) As String
Dim i As Long
Dim sByte() As Byte
Do Until i > VBA.Len(VBA.Trim(StringX)) ' - 1
i = i + 1
If VBA.Mid(StringX, i, 1) <> "%" Then
DecodeString = DecodeString & VBA.Mid(StringX, i, 1)
Else
i = i + 1
ReDim sByte(0) As Byte
sByte(0) = Val("&H" & VBA.Mid(StringX, i, 2))
If Val("&H" & VBA.Mid(StringX, i, 2)) > 128 Then
i = i + 3
ReDim Preserve sByte(1) As Byte
sByte(1) = Val("&H" & VBA.Mid(StringX, i, 2))
DecodeString = DecodeString & VBA.StrConv(sByte, vbUnicode)
Else
DecodeString = DecodeString & VBA.StrConv(sByte, vbUnicode)
End If
i = i + 1
End If
Loop
End Function
Public Function EncodeString(StringX As String) As String
Dim i As Long
Dim j As Long
Dim sByte() As Byte
For i = 0 To VBA.Len(VBA.Trim(StringX)) - 1
If (VBA.Asc(VBA.Mid(StringX, i + 1, 1)) >= VBA.Asc("0") And VBA.Asc(VBA.Mid(StringX, i + 1, 1)) <= VBA.Asc("9")) Or (VBA.Asc(VBA.Mid(StringX, i + 1, 1)) >= VBA.Asc("@") And VBA.Asc(VBA.Mid(StringX, i + 1, 1)) <= VBA.Asc("Z")) Or (Asc(VBA.Mid(StringX, i + 1, 1)) >= VBA.Asc("a") And VBA.Asc(VBA.Mid(StringX, i + 1, 1)) <= VBA.Asc("z")) Then
EncodeString = EncodeString & VBA.Mid(StringX, i + 1, 1)
Else
sByte = VBA.StrConv(VBA.Mid(StringX, i + 1, 1), vbFromUnicode)
For j = LBound(sByte) To UBound(sByte)
EncodeString = EncodeString & "%" & VBA.Hex(sByte(j))
Next j
End If
Next i
End Function
Public Function DecodeString(StringX As String) As String
Dim i As Long
Dim sByte() As Byte
Do Until i > VBA.Len(VBA.Trim(StringX)) ' - 1
i = i + 1
If VBA.Mid(StringX, i, 1) <> "%" Then
DecodeString = DecodeString & VBA.Mid(StringX, i, 1)
Else
i = i + 1
ReDim sByte(0) As Byte
sByte(0) = Val("&H" & VBA.Mid(StringX, i, 2))
If Val("&H" & VBA.Mid(StringX, i, 2)) > 128 Then
i = i + 3
ReDim Preserve sByte(1) As Byte
sByte(1) = Val("&H" & VBA.Mid(StringX, i, 2))
DecodeString = DecodeString & VBA.StrConv(sByte, vbUnicode)
Else
DecodeString = DecodeString & VBA.StrConv(sByte, vbUnicode)
End If
i = i + 1
End If
Loop
End Function
解决方案 »
- index 操作 两个问题。
- 如何分页显示呢?特别是容量大的数据
- 请教一个关于MSFgrid控件的大小的设置
- 除了用vb本身的打包向导工具来发布vb应用程序,还用什么?
- 怎么样限制用户对某個文件复制呢?
- 有没有比较经典VB+SQL SERVER的例子?急需
- 【专题开发诚聘版主】 原因有几位版主任期将满
- 关于CHM格式的帮助文件的问题!很简单的!知者不难!
- 很菜的问题,恳请各位指教!!!谢谢!!
- 春节快乐,散分+发布SuperPlayer 1.5春节版(进者有分)(在线发送到23:30)呆鱼两个多月的心血,希望您能赏脸。试用过的请在这里提意见...
- ☆☆☆一鹤的论坛地址是什么?☆☆☆
- 请教:汉字显示问题?
字符 "A" "啊"
Unicode 00 41 A0 A1
Ascii 41 A0 A1
可是怎样才能将 “214 208 185 250 49 50 51 200 203 195 241 97 98 99”
转换成字符串“中国123人民abc" 呢?
Dim sByte() As Byte
aa = Split("214 208 185 250 49 50 51 200 203 195 241 97 98 99", " ")
ReDim sByte(UBound(aa) - LBound(aa) + 1) As Byte
Dim i As Long
For i = 0 To UBound(aa) - LBound(aa)
sByte(i) = Val(aa(LBound(aa) + i))
Next i
MsgBox StrConv(sByte, vbUnicode)
Dim code(14) As Integer'code() = [ 214 208 185 250 49 50 51 200 203 195 241 97 98 99]
code(0) = 214
code(1) = 208
code(2) = 185
code(3) = 250
code(4) = 49
code(5) = 50
code(6) = 51
code(7) = 200
code(8) = 203
code(9) = 195
code(10) = 241
code(11) = 97
code(12) = 98
code(13) = 99For i = 0 To UBound(code())
'如果为ASCII字符集则显示实现
If code(i) <= 127 Then
tstr = tstr & Chr(code(i))
Else
tstr = tstr & Chr("&H" & Hex(code(i)) & Hex(code(i + 1)))
i = i + 1
End If
NextDebug.Print tstrEnd Sub