Zig
Zig
Get a Mail-Merge Replacement String by Pattern
See more Email Object Examples
Demonstrates the Chilkat Email.GetReplaceString2 method, which returns the replacement string for a previously-defined pattern/replacement pair, looked up by the pattern itself (a mail-merge feature). This example defines two pairs and looks up the replacement for one pattern by name.
Background: Where
GetReplaceString fetches a replacement by its numeric position, GetReplaceString2 fetches it by the pattern — convenient when you already know the token (say FIRST_NAME) and just want its configured substitution without scanning the whole list.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 GetReplaceString2 method, which returns the replacement string for a
// previously-defined pattern/replacement pair, looked up by the pattern itself (a
// mail-merge feature).
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 {};
// Look up the replacement for a specific pattern.
const repl = try email.getReplaceString2(alloc, "FIRST_NAME");
std.debug.print("FIRST_NAME -> {s}\n", .{repl});
}