Dart
Dart
StringBuilder SetNth
Demonstrates the SetNth method.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// The SetNth method is handy for setting a part of a delimited string.
// For example:
final sb = CkStringBuilder();
sb.append('red,blue,"green,purple",,yellow');
final delimiterChar = ',';
final exceptDoubleQuoted = true;
final exceptEscaped = true;
sb.setNth(2, 'magenta', delimiterChar, exceptDoubleQuoted, exceptEscaped);
// Prints "red,blue,magenta,,yellow"
print(sb.getAsString());
sb.setNth(3, 'orange', delimiterChar, exceptDoubleQuoted, exceptEscaped);
// Prints "red,blue,magenta,orange,yellow"
print(sb.getAsString());
// What happens if we start with an empty string?
sb.clear();
sb.setNth(2, 'apple', delimiterChar, exceptDoubleQuoted, exceptEscaped);
// Prints ",,apple"
print(sb.getAsString());
sb.setNth(0, 'orange', delimiterChar, exceptDoubleQuoted, exceptEscaped);
// Prints "orange,,apple"
print(sb.getAsString());
sb.setNth(1, 'banana', delimiterChar, exceptDoubleQuoted, exceptEscaped);
// Prints "orange,banana,apple"
print(sb.getAsString());
}