请先登录 | 注册
MYCSG.CN
在 VB 或 VB.Net 中來進行URLencode的編碼 - 文章首页返回版区
■标题:在 VB 或 VB.Net 中來進行URLencode的編碼
■作者:IPSC [2009/9/29 0:06:58]
但若想在 VB 或 VB.Net 中來進行URLencode的編碼ㄋ ??

請參考底下做法:



VB.Net 程式碼如下 :



Public Function URLEncode(ByRef strEnc As String) As String

Dim strTmp2, strChar, strTmp, strRet As String

Dim lngLoop As Integer

For lngLoop = 0 To strEnc.Length - 1

strChar = strEnc.Substring(lngLoop, 1)

Select Case Asc(strChar)

Case 48 To 57, 65 To 90, 97 To 122

strRet &= strChar

Case 32

strRet &= "+"

Case Else

strTmp = Hex(Asc(strChar))

If strTmp.Length > 4 Then strTmp = strTmp.Substring(4)

strRet &= "%" & strTmp.Substring(0, 2)

If strTmp.Length > 2 Then

strTmp2 = strTmp.Substring(2)

strRet &= IIf(IsNumeric(strTmp.Substring(2, 1)), Chr(Val("&H" & strTmp2)), "%" & strTmp2)

End If

End Select

Next

URLEncode = strRet

End Function







Public Function URLenc(ByVal strEnc As String) As String

Dim lngLoop, lngAsc As Long

Dim strChr As String

For lngLoop = 0 To strEnc.Length - 1

strChr = strEnc.Substring(lngLoop, 1)

If Math.Abs(Asc(strChr)) < 255 Then

URLenc &= strChr

Else

lngAsc = Asc(strChr)

If lngAsc < 0 Then lngAsc = lngAsc + 65536

URLenc &= "%" & Hex((lngAsc And -256) \ 255) & "%" & Hex(lngAsc And 255)

End If

Next

End Function



呼叫 :

MessageBox.Show(URLEncode("強力鎯頭 PowerHammer !"))

MessageBox.Show(URLenc("強力鎯頭 PowerHammer !"))



結果顯示 :

%B1j%A4O%EE%CF%C0Y+PowerHammer+%21

%B1%6A%A4%4F%EE%CF%C0%59 PowerHammer !






================================================================







VB6 程式碼如下 :



Public Function URLEncode(strEnc As String) As String

Dim strChar As String, strTmp As String, strTmp2 As String, strRet As String

Dim lngLoop As Long

For lngLoop = 1 To Len(strEnc)

strChar = Mid(strEnc, lngLoop, 1)

Select Case Asc(strChar)

Case 48 To 57, 65 To 90, 97 To 122

strRet = strRet & strChar

Case 32

strRet = strRet & "+"

Case Else

strTmp = Format(Hex(Asc(strChar)), "00")

strRet = strRet & "%" & Left(strTmp, 2)

strTmp2 = Mid(strTmp, 3, 2)

If Len(strTmp) > 3 Then

strRet = strRet & IIf(IsNumeric(Mid(strTmp, 3, 1)), Chr(Val("&H" & strTmp2)), "%" & strTmp2)

End If

End Select

Next

URLEncode = strRet

End Function







Public Function URLenc(strEnc As String) As String

Dim lngLoop As Long, lngAsc As Long

Dim strChr As String

For lngLoop = 1 To Len(strEnc)

strChr = Mid(strEnc, lngLoop, 1)

If Abs(Asc(strChr)) < 255 Then

URLenc = URLenc & strChr

Else

lngAsc = Asc(strChr)

If lngAsc < 0 Then lngAsc = lngAsc + 65536

URLenc = URLenc & "%" & Hex((lngAsc And -256) \ 255) & "%" & Hex(lngAsc And 255)

End If

Next

End Function



呼叫 :

MsgBox URLEncode("強力鎯頭 PowerHammer !")

MsgBox URLenc("強力鎯頭 PowerHammer !")



結果顯示 :



%B1j%A4O%EE%CF%C0Y+PowerHammer+%21

%B1%6A%A4%4F%EE%CF%C0%59 PowerHammer !






================================================================







ASP 程式碼如下(多此一舉,因為ASP本來就有Server.URLencode) :



Public Function URLEncode(strEnc)

Dim strChr, intAsc, strTmp, strTmp2, strRet, lngLoop

For lngLoop = 1 To Len(strEnc)

strChr = Mid(strEnc, lngLoop, 1)

intAsc = Asc(strChr)

If ((intAsc < 58) And (intAsc > 47)) Or ((intAsc < 91) And (intAsc > 64)) Or ((intAsc < 123) And (intAsc > 96)) Then

strRet = strRet & strChr

ElseIf intAsc = 32 Then

strRet = strRet & "+"

Else

strTmp = Hex(Asc(strChr))

strRet = strRet & "%" & Right("00" & Left(strTmp, 2), 2)

strTmp2 = Mid(strTmp, 3, 2)

If Len(strTmp) > 3 Then

If IsNumeric(Mid(strTmp, 3, 1)) Then

strRet = strRet & Chr(CInt("&H" & strTmp2))

Else

strRet = strRet & "%" & strTmp2

End If

End If

End If

Next

URLEncode = strRet

End Function







Public Function URLenc(strEnc)

Dim lngLoop, lngAsc, strChr

For lngLoop = 1 To Len(strEnc)

strChr = Mid(strEnc, lngLoop, 1)

If Abs(Asc(strChr)) < 255 Then

URLenc = URLenc & strChr

Else

lngAsc = Asc(strChr)

If lngAsc < 0 Then lngAsc = lngAsc + 65536

URLenc = URLenc & "%" & Hex((lngAsc And -256) \ 255) & "%" & Hex(lngAsc And 255)

End If

Next

End Function





呼叫 :

Response.write URLEncode("強力鎯頭 PowerHammer !")

Response.write URLenc("強力鎯頭 PowerHammer !")



結果顯示 :

%B1j%A4O%EE%CF%C0Y+PowerHammer+%21

%B1%6A%A4%4F%EE%CF%C0%59 PowerHammer !




回复/版区/上篇/下篇/发贴/仅文字/HTML
【倒序/最近21条回复】
■作者:hycu0602 [2015/11/2 12:20:59]
公司主营:



一、内资企业注册:



1,公司注册、注销;



2,注册南沙分公司、注销;



3,南沙工商代理注册,代办营业执照、工商代理注册;



4,南沙公司、南沙分公司变更名称、注册地址、股权转让、法定代表人、变更股东;



5,南沙公司年检、工商登记;



二、代理记账





公司名称:广州盈杰利财务咨询有限公司





欢迎来电:020-28650580 QQ:2598002918



手机:13602281365(手机属地:广东省广州市)



联系人:卢小姐



公司网址:http://www.gzyingjieli.com



公司地址:广州南沙区金洲金莎广场银座811室


■作者:vmit5617 [2015/10/18 16:00:59]
广州市阅江涂装公司是一家专业服务于画装饰画公司幼儿园的教育机构。<br>服务热线:13926052871&nbsp;问:2390665248&nbsp;&nbsp;<br>&nbsp&nbsp;&nbsp;&nbsp;教育在全国各地大大小小的幼儿园,幼儿园以及各种教育机构提供专业,高水准的室内外壁画,幼儿园墙上喷画,幼儿园墙上画喷花,艺术墙搭配的绘画,整个幼儿园的装修设计装修的一条龙服务的整体规划,设计和建设的所有学前教育高端的硬件设施!<br>这幅画的主要区域:广州,潮州幼儿园画画,东莞,,佛山幼儿园绘画,绘画,河源,惠州,梅州,江门幼儿园画画,揭阳幼儿园画画,茂名幼儿园画画,清远幼儿园画画,汕头幼儿园绘画,韶关汕尾幼儿园画画,深圳阳江幼儿园绘画,云浮幼儿园画画,幼儿园画画,湛江幼儿园画画,肇庆幼儿园画画,中山幼儿园画画,珠海市幼儿园....,广西,湖南,江西,中国南方等城市福建。<br>技术先进,公司采用纯手工印刷技术来绘制,从空间的传统手绘,呈现饱满的色彩效果,生动形象,强烈的立体感,有良好的感觉不同,不受时间和空间的限制,并迅速结构比传统的手工绘制的5倍。<br>材料环保-公司通过了2008年奥运会的开幕式吸引了专用漆,绿色环保,无毒,无味,颜色艳丽,饱和度高,坚固耐用,防水,耐用。<br>的收集人员,公司拥有资深的艺术家团队,专业高空画家,专业的设计团队,设计新颖,大气,活泼,设计理念一直走在国内同行业中试点位置,按施工环境,人性化设计的投资预算。广东粤江手绘墙www.haodeqh.com:<br>这篇文章摘自。欲了解更多详情,请登录:广州市墙体粉刷,墙面广州幼儿园壁画手平局。<br>&nbsp<br>
<p>
<a href="www.yjpenhui.com" target="_blank">幼儿园手绘画</a>    <a href="http://www.haodeqh.com;" target="_blank">墙绘公司</a>    <a href="www.haodeqh.com;" target="_blank">壁画</a>    <p><p>
<a href="http://www.saidetest.com/?action-login" target="_blank">广州深圳墙绘彩绘涂鸦3D立体画怎么样</a>    <a href="http://www.saidetest.com/?action-login" target="_blank">广州深圳墙绘彩绘涂鸦3D立体画怎么样</a>    <p>

(查看完整版网页)



短讯|首页|登录|算法|电脑版 .
DK MiniBBS Plus v2.0
mm0759.com
187 毫秒 .