Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>

void ChilkatSample(void)
    {
    HCkEmailW email;
    int n;
    int i;

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

    email = CkEmailW_Create();
    CkEmailW_putSubject(email,L"Hello FIRST_NAME");
    CkEmailW_putBody(email,L"Dear FIRST_NAME, welcome to CITY.");

    CkEmailW_SetReplacePattern(email,L"FIRST_NAME",L"John");
    CkEmailW_SetReplacePattern(email,L"CITY",L"Denver");

    n = CkEmailW_getNumReplacePatterns(email);

    for (i = 0; i <= n - 1; i++) {
        wprintf(L"Pattern %d: %s\n",i,CkEmailW_getReplacePattern(email,i));
    }



    CkEmailW_Dispose(email);

    }