(DataFlex) URL Encoding and Decoding
Demonstrates URL encoding and decoding.
Use ChilkatAx-win32.pkg
Procedure Test
String s
Handle hoSb
Boolean iSuccess
String sSEncoded
Integer iNumReplaced
String sTemp1
// 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
|