在VB6.0中怎么實(shí)現(xiàn)escape和unescape
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
兩套方案,一是調(diào)用JAVAscript對(duì)象,二是自己寫代碼編碼與解碼,代碼在CSDN中的以下帖子里貼出:
http://topic.csdn.net/u/20111007/19/83df5464-a787-41de-b435-938aaaed7d4f.html 方案一代碼: 復(fù)制內(nèi)容到剪貼板 程序代碼 Function Escape(ByVal pstrInput As String) As String Dim objScrCtl As Object Set objScrCtl = CreateObject("MSScriptControl.ScriptControl") objScrCtl.Language = "Javascript" Unescape = objScrCtl.Eval("escape('" & pstrInput & "')") Set objScrCtl = Nothing End Function Function Unescape(ByVal pstrInput As String) As String Dim objScrCtl As Object Set objScrCtl = CreateObject("MSScriptControl.ScriptControl") objScrCtl.Language = "Javascript" Unescape = objScrCtl.Eval("unescape('" & pstrInput & "')") Set objScrCtl = Nothing End Function 方案二代碼: 復(fù)制內(nèi)容到剪貼板 程序代碼 Function Escape(ByVal Text As String) As String Dim s As String Dim ch As String Dim iAscii As Integer Dim i As Long For i = 1 To Len(Text) ch = Mid$(Text, i, 1) Select Case ch Case "0" To "9", "a" To "z", "A" To "Z", _ "-", "_", ".", "!", "~", "*", "'", "(", ")" s = s & ch Case Else iAscii = AscW(ch) If (0 <= iAscii) And (iAscii < 255) Then s = s & ("%" & Right$("0" & Hex(iAscii), 2)) Else s = s & ("%u" & Right$("000" & Hex(iAscii), 4)) End If End Select Next Escape = s End Function Function Unescape(ByVal Text As String) As String Dim i As Long For i = 1 To Len(Text) If Mid$(Text, i, 2) = "%u" Then Text = Replace$(Text, Mid$(Text, i, 6), ChrW$(AscW(ChrW$("&H" & Mid$(Text, i + 2, 4))))) If Mid$(Text, i, 1) = "%" Then Text = Replace$(Text, Mid$(Text, i, 3), Chr$(Asc(Chr$("&H" & Mid$(Text, i + 1, 2))))) Next i Unescape = Text End Function 該文章在 2013/12/11 14:48:41 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |