Sample code for 30+ languages & platforms
PureBasic

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

PureBasic
IncludeFile "CkEmail.pb"

Procedure ChilkatExample()

    ;  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).

    email.i = CkEmail::ckCreate()
    If email.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkEmail::setCkSubject(email, "Hello FIRST_NAME")
    CkEmail::setCkBody(email, "Dear FIRST_NAME, welcome to CITY.")

    CkEmail::ckSetReplacePattern(email,"FIRST_NAME","John")
    CkEmail::ckSetReplacePattern(email,"CITY","Denver")

    ;  Look up the replacement for a specific pattern.
    repl.s = CkEmail::ckGetReplaceString2(email,"FIRST_NAME")
    Debug "FIRST_NAME -> " + repl


    CkEmail::ckDispose(email)


    ProcedureReturn
EndProcedure