Categories
Common

QlikView VBScript URL Encode

'/* Restricted Party Screening   */
'/* URL ENCODING                 */
'/* Adapted: philipp@frenzel.net */
Public Function Encode_UTF8(astr)
    Dim c
    Dim utftext
    utftext = ""
    If isNull(astr) = false or astr <> "" Then
      astr = Replace(astr, "’", "'") 'replacing the apostrophe
      astr = Replace(astr, "–", "-") 'replacing the emdash with minus sign
      For n = 1 To Len(astr)
        c = Asc(Mid(astr, n, 1))
        If c < 128 Then
          utftext = utftext + Mid(astr, n, 1)
        ElseIf ((c > 127) And (c < 2048)) Then
          utftext = utftext + Chr(((c \ 64) Or 192))
          utftext = utftext + Chr(((c And 63) Or 128))
        Else
          utftext = utftext + Chr(((c \ 144) Or 234))
          utftext = utftext + Chr((((c \ 64) And 63) Or 128))
          utftext = utftext + Chr(((c And 63) Or 128))
        End If
      Next
    End If
    Encode_UTF8 = utftext
End Function

Leave a Reply