Sample code for 30+ languages & platforms
Android™

Count the Replace Patterns Set on an Email

See more Email Object Examples

Demonstrates the read-only Chilkat Email.NumReplacePatterns property, which returns how many replacement patterns have been set via SetReplacePattern. When replacement patterns are present, the email bodies and header fields are modified by applying the search/replacement strings during the sending process. Pattern indexes are zero-based. This example sets two patterns and prints the count.

Background: This is Chilkat's built-in mail merge. You compose one email containing placeholder tokens (for example FIRST_NAME or CITY), register each token and its replacement with SetReplacePattern, and the substitutions are applied when the message is sent — letting you personalize a bulk mailing without building a separate message for every recipient.

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 read-only Email.NumReplacePatterns property.  Replace patterns are
    //  search/replacement strings (set with SetReplacePattern) that are applied to the email
    //  bodies and header fields during mail-merge sending.  Indexes are zero-based.

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

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

    Log.i(TAG, "NumReplacePatterns = " + String.valueOf(email.get_NumReplacePatterns()));

  }

  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."
  }
}