Sample code for 30+ languages & platforms
Xbase++

MIME Header Q and B Encoding and Decoding

See more Encryption Examples

Demonstrates how to Q and B encode/decode.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSb
LOCAL oSb2

nSuccess := 0

oSb := CreateObject("Chilkat.StringBuilder")

oSb:Append("This is a test")

? oSb:GetEncoded("B", "utf-8")
//  output is:
//  =?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=

? oSb:GetEncoded("Q", "iso-8859-1")
//  output is:
//  =?utf-8?Q?This_is_a_test?=

oSb2 := CreateObject("Chilkat.StringBuilder")

oSb2:Append("=?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=")
oSb2:Decode("B", "utf-8")
? oSb2:GetAsString()

//  output is:
//  This is a test

oSb2:Clear()
oSb2:Append("=?utf-8?Q?This_is_a_test?=")
oSb2:Decode("Q", "utf-8")
? oSb2:GetAsString()

//  output is:
//  This is a test

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

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

oSb:destroy()
oSb2:destroy()