(PureBasic) StringBuilder Encode
Demonstrates the Chilkat StringBuilder Encode method.
IncludeFile "CkStringBuilder.pb"
Procedure ChilkatExample()
s.s = "The quick brown fox jumps over the lazy dog"
sb.i = CkStringBuilder::ckCreate()
If sb.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkStringBuilder::ckAppend(sb,s)
; output: The quick brown fox jumps over the lazy dog
Debug CkStringBuilder::ckGetAsString(sb)
CkStringBuilder::ckEncode(sb,"base64","utf-8")
; output: VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==
Debug CkStringBuilder::ckGetAsString(sb)
CkStringBuilder::ckDecode(sb,"base64","utf-8")
; output: The quick brown fox jumps over the lazy dog
Debug CkStringBuilder::ckGetAsString(sb)
; Now encode to hex..
CkStringBuilder::ckEncode(sb,"hex","utf-8")
; output: 54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F67
Debug CkStringBuilder::ckGetAsString(sb)
CkStringBuilder::ckDecode(sb,"hex","utf-8")
; URL encode
CkStringBuilder::ckEncode(sb,"url","utf-8")
Debug CkStringBuilder::ckGetAsString(sb)
CkStringBuilder::ckDecode(sb,"url","utf-8")
; base64url
CkStringBuilder::ckEncode(sb,"base64url","utf-8")
Debug CkStringBuilder::ckGetAsString(sb)
; other possible encodings include modbase64, base32, base58, quoted-printable, url_rfc1738, url_rfc2396, url_rfc3986, and fingerprint
CkStringBuilder::ckDispose(sb)
ProcedureReturn
EndProcedure
|