vb中怎么写URLEncode编码?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vb中怎么写URLEncode编码?相关的知识,希望对你有一定的参考价值。

vb中怎么写URLEncode编码?
我想转换的字 例如是:我们

在网上找到的

Public Function URLEncoding(ByVal vstrIn As String) As String
strreturn = ""
Dim i
Dim thisChr
For i = 1 To Len(vstrIn)
thisChr = Mid(vstrIn, i, 1)
If Abs(Asc(thisChr)) < &HFF Then
If thisChr = " " Then
strreturn = strreturn & "+"
Else
If InStr(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.", thisChr) > 0 Then
strreturn = strreturn & thisChr
Else
strreturn = strreturn & "%" & IIf(Asc(thisChr) > 16, "", "0") & Hex(Asc(thisChr))
End If
End If
Else
innerCode = Asc(thisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00) \ &HFF
Low8 = innerCode And &HFF
strreturn = strreturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
URLEncoding = strreturn
End Function

都是 转换成 %CE%D2%C3%C7 这个的,

而不是转成 %E6%88%91%E4%BB%AC 这个的哦

请大家帮帮忙哦!!谢谢
那VB里有CodePage是65001和936两种情况的么??
获得的代码 象这个帖子差不多! 不过是ASP的。我想要VB转换的。
http://zhidao.baidu.com/question/6912615.html?si=4

不知道怎么写第2个代码的function 网上没找到哦。

这个程序就是vb的源程序.
"我们" 转换成"%CE%D2%C3%C7 ",这是asc的编码
"%E6%88%91%E4%BB%AC " 是"我们"的UTF-8的编码.

用这个函数可以获得UTF-8编码

Function GBtoUTF8(szInput)
Dim wch, uch, szRet
Dim x
Dim nAsc, nAsc2, nAsc3

'如果输入参数为空,则退出函数
If szInput = "" Then
GBtoUTF8 = szInput
Exit Function
End If

'开始转换
For x = 1 To Len(szInput)
wch = Mid(szInput, x, 1)
nAsc = AscW(wch)

If nAsc < 0 Then nAsc = nAsc + 65536

If (nAsc And &HFF80) = 0 Then
szRet = szRet & wch
Else
If (nAsc And &HF000) = 0 Then
uch = "%" & Hex(((nAsc \ 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80)
szRet = szRet & uch
Else
uch = "%" & Hex((nAsc \ 2 ^ 12) Or &HE0) & "%" & _
Hex((nAsc \ 2 ^ 6) And &H3F Or &H80) & "%" & _
Hex(nAsc And &H3F Or &H80)
szRet = szRet & uch
End If
End If
Next
GBtoUTF8 = szRet
End Function

参考资料:http://www.asp.org.cn/vbscript/2007-1-25/1961.htm

参考技术A   vb中URLEncode编码的写法:
  代码如下:
  Public Function URLEncode(ByVal strParameter As String) As String
  Dim s As String
  Dim I As Integer
  Dim intValue As Integer

  Dim TmpData() As Byte

  s = ""
  TmpData = StrConv(strParameter, vbFromUnicode)
  For I = 0 To UBound(TmpData)
  intValue = TmpData(I)
  If (intValue >= 48 And intValue <= 57) Or _
  (intValue >= 65 And intValue <= 90) Or _
  (intValue >= 97 And intValue <= 122) Then
  s = s & Chr(intValue)
  ElseIf intValue = 32 Then
  s = s & "+"
  Else
  s = s & "%" & Hex(intValue)
  End If
  Next I
  URLEncode = s
  end Function
参考技术B 多谢楼下回答,解决大问题了。

以上是关于vb中怎么写URLEncode编码?的主要内容,如果未能解决你的问题,请参考以下文章

什么是urlencode编码

Server.URLEncode 编码是怎么决定的?

如果在textbook中输入小数,按ctrl结束,则弹出提示窗口,用VB编码怎么写?

php 中urlencode的作用是啥不用会怎么样?

iOS中urlencode

Owin的URL编码怎么搞?以前都是HttpUtility.UrlEncode之类的,现在连system.web都没了,肿么办?