Zig
Zig
Get a Mail-Merge Replace Pattern
See more Email Object Examples
Demonstrates the Chilkat Email.GetReplacePattern method, which returns a replacement pattern — the search string — previously defined for mail-merge operations with SetReplacePattern. The index is zero-based. This example defines two patterns and enumerates them.
Background: In Chilkat's mail-merge, each entry is a pattern (a placeholder token such as
FIRST_NAME) paired with a replacement string. GetReplacePattern retrieves the search side of the pair at a given index; GetReplaceString retrieves the matching replacement. Reading them back is useful for inspecting or logging exactly which substitutions will be applied when the message is sent.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// Demonstrates the GetReplacePattern method, which returns a replacement pattern (the
// search string) previously defined for mail-merge operations with SetReplacePattern.
// The index is zero-based.
const email = try chilkat.Email.init();
defer email.deinit();
email.setSubject("Hello FIRST_NAME");
email.setBody("Dear FIRST_NAME, welcome to CITY.");
email.setReplacePattern("FIRST_NAME", "John") catch {};
email.setReplacePattern("CITY", "Denver") catch {};
const n = email.getNumReplacePatterns();
var i: i32 = 0;
i = 0;
while (i < n) : (i += 1) {
std.debug.print("Pattern {d}: {s}\n", .{ i, try email.getReplacePattern(alloc, i) });
}
}