Sample code for 30+ languages & platforms
PowerBuilder

MIME Header Q and B Encoding and Decoding

See more Encryption Examples

Demonstrates how to Q and B encode/decode.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Sb
oleobject loo_Sb2

li_Success = 0

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

loo_Sb.Append("This is a test")

Write-Debug loo_Sb.GetEncoded("B","utf-8")
// output is:
// =?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=

Write-Debug loo_Sb.GetEncoded("Q","iso-8859-1")
// output is:
// =?utf-8?Q?This_is_a_test?=

loo_Sb2 = create oleobject
li_rc = loo_Sb2.ConnectToNewObject("Chilkat.StringBuilder")

loo_Sb2.Append("=?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=")
loo_Sb2.Decode("B","utf-8")
Write-Debug loo_Sb2.GetAsString()

// output is:
// This is a test

loo_Sb2.Clear()
loo_Sb2.Append("=?utf-8?Q?This_is_a_test?=")
loo_Sb2.Decode("Q","utf-8")
Write-Debug loo_Sb2.GetAsString()

// output is:
// This is a test

// "B" or "Q" will decode both B and Q.
loo_Sb2.Clear()
loo_Sb2.Append("=?utf-8?Q?This_is_a_test?= 123 =?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=")
loo_Sb2.Decode("Q","utf-8")
Write-Debug loo_Sb2.GetAsString()

// output is:
// This is a test 123 This is a test


destroy loo_Sb
destroy loo_Sb2