Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Email
integer n
integer i

//  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.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Email.Subject = "Hello FIRST_NAME"
loo_Email.Body = "Dear FIRST_NAME, welcome to CITY."

loo_Email.SetReplacePattern("FIRST_NAME","John")
loo_Email.SetReplacePattern("CITY","Denver")

n = loo_Email.NumReplacePatterns

for i = 0 to n - 1
    Write-Debug loo_Email.GetReplacePattern(i) + " -> " + loo_Email.GetReplaceString(i)
next


destroy loo_Email