Sample code for 30+ languages & platforms
Zig

StringBuilder ReplaceBetween

Demonstrates the ReplaceBetween method.

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();
    sb.append("<company><industry>Software</industry><name>Chilkat Software</name><abc>Abc Software</abc><name>Xyz Software</name></company>") catch {};

    // The ReplaceBetween method restricts the replacements to only
    // the parts that occur between two delimiter strings.

    // For example:
    const num_replacements = sb.replaceBetween("<name>", "</name>", "Software", "Technology");

    // The number of replacements should be 2.
    std.debug.print("numReplacements = {d}\n", .{num_replacements});

    // The sb now contains:
    // <company><industry>Software</industry><name>Chilkat Technology</name><abc>Abc Software</abc><name>Xyz Technology</name></company>
    std.debug.print("{s}\n", .{try sb.getAsString(alloc)});
}