Sample code for 30+ languages & platforms
Zig

Appending Strings to BinData

Demonstrates appending strings to a BinData..

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const bin_data1 = try chilkat.BinData.init();
    defer bin_data1.deinit();

    // Append a string using a 1-byte per char encoding
    bin_data1.appendString("This is a test", "windows-1252") catch {};
    std.debug.print("{s}\n", .{try bin_data1.getEncoded(alloc, "hex")});
    // The bytes contained within the binData1 (in hex) are: 54,68,69,73,20,69, ...

    const bin_data2 = try chilkat.BinData.init();
    defer bin_data2.deinit();

    // Append a string using a 2-byte per char encoding
    bin_data2.appendString("This is a test", "utf-16") catch {};
    std.debug.print("{s}\n", .{try bin_data2.getEncoded(alloc, "hex")});
    // The bytes contained within the binData2 (in hex) are: 54,00,68,00,69,00,73,00,20,00,69,00, ...
}