Zig
Zig
StringBuilder ReplaceWord
Demonstrates the ReplaceWord 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 sb = try chilkat.StringBuilder.init();
defer sb.deinit();
sb.append("forest, lumber, lumberjack, jack, timberland") catch {};
// The ReplaceWord method replaces word occurances.
// For example:
var num_replacements: i32 = sb.replaceWord("lumber", "timber");
num_replacements = sb.replaceWord("jack", "joe");
// The string content is now:
// forest, timber, lumberjack, joe, timberland
std.debug.print("{s}\n", .{try sb.getAsString(alloc)});
}