Sample code for 30+ languages & platforms
Android™

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 Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkEmail email = new CkEmail();
    email.put_Subject("Hello FIRST_NAME");
    email.put_Body("Dear FIRST_NAME, welcome to CITY.");

    email.SetReplacePattern("FIRST_NAME","John");
    email.SetReplacePattern("CITY","Denver");

    int n = email.get_NumReplacePatterns();
    int i;
    for (i = 0; i <= n - 1; i++) {
        Log.i(TAG, "Pattern " + String.valueOf(i) + ": " + email.getReplacePattern(i));
        }


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}