Zig
Zig
StringBuilder GetEncoded
Demonstrates the Chilkat StringBuilder GetEncoded method.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const s = "The quick brown fox jumps over the lazy dog";
const sb = try chilkat.StringBuilder.init();
defer sb.deinit();
sb.append(s) catch {};
// output: The quick brown fox jumps over the lazy dog
std.debug.print("{s}\n", .{try sb.getAsString(alloc)});
// Get the string encoded to base64, without changing the contents of sb.
// output: VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==
std.debug.print("{s}\n", .{try sb.getEncoded(alloc, "base64", "utf-8")});
// The contents of sb are not changed..
// output: The quick brown fox jumps over the lazy dog
std.debug.print("{s}\n", .{try sb.getAsString(alloc)});
}