So I had to write a function to URL encode a string. There is an API (UrlEscape) to do url encoding (aka percent-encoding), but its limited to strings of 2083 (2048+32+3) characters or less. I have a case where I need to do x-www-form-urlencoding of a huge chunk of XML (because something out of my control was designed by morons).

Anyways, here is my 5 min solution in case someone else needs it in the future (likely me ;-) ).

Code:
Function Dec2Hex Integer iDec Returns String
    String sHex
    
    Repeat
        Move (Mid ("0123456789ABCDEF", 1, ((iDec iand $0F) + 1)) + sHex) to sHex
        Move (iDec / $10) to iDec
    Until (iDec = 0)
    
    If (Mod (Length (sHex), 2) <> 0) Begin
    Move ("0" + sHex) to sHex
    End
    
    Function_Return sHex
End_Function    

Function URLEncode String encodeString Returns String
    Integer i
    
    Move (Replaces("%", encodeString, "%25")) to encodeString
    
    For i from 0 to 31
        Move (Replaces(Character(i), encodeString, "%" + Dec2Hex(Self, i))) to encodeString
    Loop
    For i from 128 to 255
        Move (Replaces(Character(i), encodeString, "%" + Dec2Hex(Self, i))) to encodeString
    Loop

    Move (Replaces("$", encodeString, "%24")) to encodeString
    Move (Replaces("&", encodeString, "%26")) to encodeString
    Move (Replaces("+", encodeString, "%2B")) to encodeString
    Move (Replaces(",", encodeString, "%2C")) to encodeString
    Move (Replaces("/", encodeString, "%2F")) to encodeString
    Move (Replaces(":", encodeString, "%3A")) to encodeString
    Move (Replaces(";", encodeString, "%3B")) to encodeString
    Move (Replaces("=", encodeString, "%3D")) to encodeString
    Move (Replaces("?", encodeString, "%3F")) to encodeString
    Move (Replaces("@", encodeString, "%40")) to encodeString
    Move (Replaces(" ", encodeString, "%20")) to encodeString
    Move (Replaces('"', encodeString, "%22")) to encodeString
    Move (Replaces("<", encodeString, "%3C")) to encodeString
    Move (Replaces(">", encodeString, "%3E")) to encodeString
    Move (Replaces("#", encodeString, "%23")) to encodeString
    Move (Replaces("{", encodeString, "%7B")) to encodeString
    Move (Replaces("}", encodeString, "%7D")) to encodeString
    Move (Replaces("|", encodeString, "%7C")) to encodeString
    Move (Replaces("\", encodeString, "%5C")) to encodeString
    Move (Replaces("^", encodeString, "%5E")) to encodeString
    Move (Replaces("~", encodeString, "%7E")) to encodeString
    Move (Replaces("[", encodeString, "%5B")) to encodeString
    Move (Replaces("]", encodeString, "%5D")) to encodeString
    Move (Replaces("`", encodeString, "%60")) to encodeString
    
    Function_Return encodestring
End_Function
Anyone got a better way of doing it?

OLIVER