Sample code for 30+ languages & platforms
Lua

Get a Mail-Merge Replacement String by Index

See more Email Object Examples

Demonstrates the Chilkat Email.GetReplaceString method, which returns the replacement string for the Nth previously-defined pattern/replacement pair (a mail-merge feature). The index is zero-based and corresponds to the same index used by GetReplacePattern. This example defines two pairs and prints each pattern with its replacement.

Background: Pairing GetReplacePattern (the token to find) with GetReplaceString (the text to substitute) at the same index lets you walk the full mail-merge table. Retrieving a replacement by its position is handy when enumerating all substitutions; to look one up by its pattern instead, use GetReplaceString2.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Demonstrates the GetReplaceString method, which returns the replacement string for the
-- Nth previously-defined pattern/replacement pair (a mail-merge feature).  The index is
-- zero-based and corresponds to the same index used by GetReplacePattern.

local email = chilkat.Email.new()
email.subject = "Hello FIRST_NAME"
email.body = "Dear FIRST_NAME, welcome to CITY."

email:set_replace_pattern("FIRST_NAME", "John")
email:set_replace_pattern("CITY", "Denver")

local n = email.num_replace_patterns
for i = 0, n - 1 do
    print(email:get_replace_pattern(i) .. " -> " .. email:get_replace_string(i))
end