Sample code for 30+ languages & platforms
DataFlex

URL Encoding and Decoding

See more Encryption Examples

Demonstrates URL encoding and decoding.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    String s
    Handle hoSb
    String sSEncoded
    Integer iNumReplaced
    String sTemp1

    Move False To iSuccess

    // To URL encoding a string:
    Move "Why a > b?" To s

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
    If (Not(IsComObjectCreated(hoSb))) Begin
        Send CreateComObject of hoSb
    End
    Get ComAppend Of hoSb s To iSuccess

    // URL encode the string.
    Get ComEncode Of hoSb "url" "utf-8" To iSuccess

    // Show the URL encoded string:
    Get ComGetAsString Of hoSb To sSEncoded
    Showln sSEncoded

    // The result is:  Why%20a%20%3E%20b%3F

    // If you prefer "+" instead of "%20" for SPACE chars:
    Get ComReplace Of hoSb "%20" "+" To iNumReplaced
    Get ComGetAsString Of hoSb To sTemp1
    Showln sTemp1

    // Output is:   Why+a+%3E+b%3F

    // To decode:
    Get ComDecode Of hoSb "url" "utf-8" To iSuccess
    Get ComGetAsString Of hoSb To sTemp1
    Showln sTemp1

    // Result is: Why a > b?


End_Procedure