Sample code for 30+ languages & platforms
PowerBuilder

URL Encoding and Decoding

See more Encryption Examples

Demonstrates URL encoding and decoding.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
string s
oleobject loo_Sb
string ls_SEncoded
integer li_NumReplaced

li_Success = 0

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

loo_Sb = create oleobject
li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_Sb
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Sb.Append(s)

// URL encode the string.
loo_Sb.Encode("url","utf-8")

// Show the URL encoded string:
ls_SEncoded = loo_Sb.GetAsString()
Write-Debug ls_SEncoded

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

// If you prefer "+" instead of "%20" for SPACE chars:
li_NumReplaced = loo_Sb.Replace("%20","+")
Write-Debug loo_Sb.GetAsString()

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

// To decode:
loo_Sb.Decode("url","utf-8")
Write-Debug loo_Sb.GetAsString()

// Result is: Why a > b?


destroy loo_Sb