Sample code for 30+ languages & platforms
React Native

StringBuilder SetNth

Demonstrates the SetNth method.

Chilkat React Native Downloads

React Native
import { StringBuilder } from '@chilkat/react-native'

function chilkatExample() {
  // The SetNth method is handy for setting a part of a delimited string.
  // For example:

  const sb = new StringBuilder();
  sb.append('red,blue,"green,purple",,yellow');

  const delimiterChar = ',';
  const exceptDoubleQuoted = true;
  const exceptEscaped = true;

  sb.setNth(2, 'magenta', delimiterChar, exceptDoubleQuoted, exceptEscaped);
  // Prints "red,blue,magenta,,yellow"
  console.log(sb.getAsString());

  sb.setNth(3, 'orange', delimiterChar, exceptDoubleQuoted, exceptEscaped);
  // Prints "red,blue,magenta,orange,yellow"
  console.log(sb.getAsString());

  // What happens if we start with an empty string?
  sb.clear();

  sb.setNth(2, 'apple', delimiterChar, exceptDoubleQuoted, exceptEscaped);
  // Prints ",,apple"
  console.log(sb.getAsString());

  sb.setNth(0, 'orange', delimiterChar, exceptDoubleQuoted, exceptEscaped);
  // Prints "orange,,apple"
  console.log(sb.getAsString());

  sb.setNth(1, 'banana', delimiterChar, exceptDoubleQuoted, exceptEscaped);
  // Prints "orange,banana,apple"
  console.log(sb.getAsString());
}