Android™
Android™
StringBuilder SetNth
Demonstrates the SetNth method.Chilkat Android™ Downloads
// 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);
// The SetNth method is handy for setting a part of a delimited string.
// For example:
CkStringBuilder sb = new CkStringBuilder();
sb.Append("red,blue,\"green,purple\",,yellow");
String delimiterChar = ",";
boolean exceptDoubleQuoted = true;
boolean exceptEscaped = true;
sb.SetNth(2,"magenta",delimiterChar,exceptDoubleQuoted,exceptEscaped);
// Prints "red,blue,magenta,,yellow"
Log.i(TAG, sb.getAsString());
sb.SetNth(3,"orange",delimiterChar,exceptDoubleQuoted,exceptEscaped);
// Prints "red,blue,magenta,orange,yellow"
Log.i(TAG, sb.getAsString());
// What happens if we start with an empty string?
sb.Clear();
sb.SetNth(2,"apple",delimiterChar,exceptDoubleQuoted,exceptEscaped);
// Prints ",,apple"
Log.i(TAG, sb.getAsString());
sb.SetNth(0,"orange",delimiterChar,exceptDoubleQuoted,exceptEscaped);
// Prints "orange,,apple"
Log.i(TAG, sb.getAsString());
sb.SetNth(1,"banana",delimiterChar,exceptDoubleQuoted,exceptEscaped);
// Prints "orange,banana,apple"
Log.i(TAG, sb.getAsString());
}
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."
}
}