gpt4 book ai didi

utf-8 - 如何解码包含阿拉伯字符的(百分比编码 URL)?

转载 作者:行者123 更新时间:2023-12-03 14:32:44 26 4
gpt4 key购买 nike

我想转换所有语言的百分比编码 URL,但 vb6 仅支持英语。

我已经测试了以下代码。但它只能转换英文字符:

Private Sub Form_Load()
THE_ARABIC_URL = "%D8%AF%D8%B4%D9%85%D9%86%DB%8C+%D8%AF%D8%B1+%D8%A7%D8%B9%D9%85%D8%A7%D9%82-2019-12-09+01%3A09%3A00"
MsgBox URLDecode(THE_ARABIC_URL)
End Sub

Private Function URLDecode(ByVal txt As String) As String
Dim txt_len As Integer
Dim i As Integer
Dim ch As String
Dim digits As String
Dim result As String

result = ""
txt_len = Len(txt)
i = 1
Do While i <= txt_len
' Examine the next character.
ch = Mid$(txt, i, 1)
If ch = "+" Then
' Convert to space character.
result = result & " "
ElseIf ch <> "%" Then
' Normal character.
result = result & ch
ElseIf i > txt_len - 2 Then
' No room for two following digits.
result = result & ch
Else
' Get the next two hex digits.
digits = Mid$(txt, i + 1, 2)
result = result & Chr$(CInt("&H" & digits))
i = i + 2
End If
i = i + 1
Loop

URLDecode = result
End Function

来源: VB Helper .

最佳答案

如果您想手动执行此操作,则必须编写一个支持 UTF-8 的函数。但是,还有一种更简单的方法,即使用 MSScriptControl.ScriptControl 依赖 JScript 引擎。目的。您可以使用 this answer 中的函数.

这是一个完整的例子:

Public JSEngine

Public Sub InitializeJSEngine()
Set JSEngine = CreateObject("MSScriptControl.ScriptControl")
JSEngine.Language = "JScript"
End Sub

Function UrlDecode(s) As String
UrlDecode = Replace(s, "+", " ")
UrlDecode = JSEngine.CodeObject.decodeURIComponent(UrlDecode)
End Function

Private Sub Form_Load()
' Make sure this is called before calling `UrlDecode`.
InitializeJSEngine
End Sub

Private Sub btnDecode_Click()
' Prints: "دشمني در اعماق-2019-12-09 01:09:00"
' ..which is Persian, not Arabic ;‑)
Debug.Print UrlDecode("%D8%AF%D8%B4%D9%85%D9%86%DB%8C+%D8%AF%D8%B1+%D8%A7%D8%B9%D9%85%D8%A7%D9%82-2019-12-09+01%3A09%3A00")
End Sub

关于utf-8 - 如何解码包含阿拉伯字符的(百分比编码 URL)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59250653/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com