Sample code for 30+ languages & platforms
Lianja

Append Encoded Binary Data to StringBuilder

Demonstrates how to append encoded binary data to the contenets of a StringBuilder.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

loBd = createobject("CkBinData")

llSuccess = loBd.LoadFile("qa_data/jpg/starfish.jpg")
if (llSuccess = .F.) then
    ? "Failed to load file."
    release loBd
    return
endif

// For example, let's say we want construct simple JSON containing the base64 representation of the above JPG file.
loSb = createobject("CkStringBuilder")
loSb.Append('{ "jpg": "')
// GetEncodedSb appends the enocded representation of the binary data to the StringBuiler passed in the 2nd arg.
loBd.GetEncodedSb("base64",loSb)
loSb.Append('" }')

? loSb.GetAsString()

// Output looks like this:
//  { "jpg": "/9j/4AAQSkZJRgABAg...rcQ+vo//2Q==" }


release loBd
release loSb