Sample code for 30+ languages & platforms
Zig Requires Chilkat v11.1.0+

HTML Entity Encode and Decode in StringBuilder

Demonstrates HTML encoding and decoding the contents of a StringBuilder.

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 sb = try chilkat.StringBuilder.init();
    defer sb.deinit();

    const s = "< é ü ç Ω Hello & World ✓ >";
    sb.append(s) catch {};

    sb.encode("html", "utf-8") catch {};
    std.debug.print("{s}\n", .{try sb.getAsString(alloc)});

    // Output:
    // < &eacute; &uuml; &ccedil; &ohm; Hello & World &check; >

    // To decode:
    sb.decode("html", "utf-8") catch {};
    std.debug.print("{s}\n", .{try sb.getAsString(alloc)});

    // Output:
    // < é ü ç Ω Hello & World ✓ >
}