About This Code
Brief Description:
LotusScript version of JavaScript's Unescape function
Notes Version:
R5.x, R6.x
Last Modified:
20 Aug 2002
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
Thanks to Emanuel Moecklin for posting this to the ldd Gold forum!
Function Unescape(s As String) As String
%REM
Dencodes a string from the "x-www-form-urlencoded" form, enhanced with the UTF-8-in-URL proposal. This is the official
standard to encode URL's to support any possible character set (all Unicode characters).
%END REM
Dim result As String
Dim b As Long, c As Long
Dim i As Integer
Dim sumb As Long
For i = 1 To Len(s)
c = Uni(Mid$(s, i, 1))
Select Case c
Case Uni("%"):
b = Cint("&H"+Mid$(s, i+1,2))
i = i + 2
Case Uni("+")
b = Uni(" ")
Case Else
b = c
End Select
' Decode byte b as UTF-8, sumb collects incomplete chars
If (b And &Hc0) = &H80 Then
sumb = (sumb*64) Or (b And &H3f)
Else
If (sumb<>0) Then
result = result & Uchr(sumb)
End If
If (b And &H80) = 0 Then
sumb = b
Else
sumb = b And &H1f
End If
End If
Next
If (sumb<>0) Then
result = result & Uchr(sumb)
End If
Unescape = result
End Function
Usage / Example