(PureBasic) MIME Header Q and B Encoding and Decoding
Demonstrates how to Q and B encode/decode.
IncludeFile "CkStringBuilder.pb"
Procedure ChilkatExample()
sb.i = CkStringBuilder::ckCreate()
If sb.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
CkStringBuilder::ckAppend(sb,"This is a test")
Debug CkStringBuilder::ckGetEncoded(sb,"B","utf-8")
; output is:
; =?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=
Debug CkStringBuilder::ckGetEncoded(sb,"Q","iso-8859-1")
; output is:
; =?utf-8?Q?This_is_a_test?=
sb2.i = CkStringBuilder::ckCreate()
If sb2.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkStringBuilder::ckAppend(sb2,"=?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=")
CkStringBuilder::ckDecode(sb2,"B","utf-8")
Debug CkStringBuilder::ckGetAsString(sb2)
; output is:
; This is a test
CkStringBuilder::ckClear(sb2)
CkStringBuilder::ckAppend(sb2,"=?utf-8?Q?This_is_a_test?=")
CkStringBuilder::ckDecode(sb2,"Q","utf-8")
Debug CkStringBuilder::ckGetAsString(sb2)
; output is:
; This is a test
; "B" or "Q" will decode both B and Q.
CkStringBuilder::ckClear(sb2)
CkStringBuilder::ckAppend(sb2,"=?utf-8?Q?This_is_a_test?= 123 =?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=")
CkStringBuilder::ckDecode(sb2,"Q","utf-8")
Debug CkStringBuilder::ckGetAsString(sb2)
; output is:
; This is a test 123 This is a test
CkStringBuilder::ckDispose(sb)
CkStringBuilder::ckDispose(sb2)
ProcedureReturn
EndProcedure
|