Sample code for 30+ languages & platforms
Zig

StringBuilder RemoveAfterFinal

Demonstrates the StringBuilder.RemoveAfterFinal method.

The GetBefore method was added in Chilkat v9.5.0.77

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();
    try sb.append("abc::def::ghi");

    // The RemoveAfterFinal method removes the chars after the final occurrence of the marker.
    // It also removes the marker string.
    // If the marker is not found, then nothing is removed and the method returns false.
    const marker = "::";
    const b_found = if (sb.removeAfterFinal(marker)) true else |_| false;

    std.debug.print("bFound = {}\n", .{b_found});
    std.debug.print("sb contains: {s}\n", .{try sb.getAsString(alloc)});

    // Output is:
    // bFound = true
    // sb contains: abc::def
}