1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
Private Function URIEncodeUTF8(ByVal sTxt As String) As String
Dim sUTF8 As String, lCode As Long, i As Integer, abyTxt() As Byte
abyTxt = StrConv(sTxt, vbUnicode)
For i = 0 To UBound(abyTxt) Step 4
lCode = abyTxt(i) + abyTxt(i + 1) * &H10 + abyTxt(i + 2) * &H100 + abyTxt(i + 3) * &H1000
If lCode < &H80 Then 'de 0 à 127
sUTF8 = sUTF8 & Format(Hex(lCode), "%@@")
ElseIf lCode < &H800 Then 'de 128 à 2047
sUTF8 = sUTF8 & Format(Hex(&HC0 Or (lCode \ &H40)) & _
Hex(&H80 Or (lCode And &H3F)), "%@@%@@")
ElseIf lCode < &H10000 Then 'de 2048 à 65535
sUTF8 = sUTF8 & Format(Hex(&HE0 Or (lCode \ &H1000)) & _
Hex(&H80 Or ((lCode \ &H40) And &H3F)) & _
Hex(&H80 Or (lCode And &H3F)), "%@@%@@%@@")
Else '>= 65536
sUTF8 = sUTF8 & Format(Hex(&HF0 Or (lCode \ &H40000)) & _
Hex(&H80 Or ((lCode \ &H1000) And &H3F)) & _
Hex(&H80 Or ((lCode \ &H40) And &H3F)) & _
Hex(&H80 Or (lCode And &H3F)), "%@@%@@%@@%@@")
End If
Next i
'Remplace les éventuels espaces par 0
sUTF8 = Replace(sUTF8, " ", "0")
URIEncodeUTF8 = sUTF8
End Function |
Partager