Visual Basic 6 function "rawurldecode"

Go back

Below you'll find the source for the Visual Basic 6 function rawurldecode.

Attribute VB_Name = "modRawurldecode"
' This function is downloaded from:
' http://www.stefanthoolen.nl/archive/vb6-functions/
' 
' You may freely distribute this file but please leave all comments, including this one, in it.
' 
' @Author Stefan Thoolen <mail@stefanthoolen.nl>

Option Explicit

''
' Decode URL-encoded strings
' Same syntax as the PHP function 'rawurldecode'
' See also: http://www.php.net/manual/en/function.rawurldecode.php
' @param    String  tstr        The encoded string
' @return   String              A normal string
' @author   Stefan Thoolen <mail@stefanthoolen.nl>
Public Function rawurldecode(tstr As String) As String
    Dim i As Integer, ret As String, s As String
    For i = 1 To Len(tstr)
        s = Mid(tstr, i, 1)
        If s = "%" Then s = Chr("&h" & Mid(tstr, i + 1, 2)): i = i + 2
        ret = ret & s
    Next i
    rawurldecode = ret
End Function