lindexSplit method

List<String> lindexSplit(
  1. String text,
  2. List<int> indices
)

Implementation

List<String> lindexSplit(String text, List<int> indices) {
  List<int> args = [];
  args.add(0);

  for (int data in indices) {
    args.add(data + 1);
  }
  args.add(text.length + 1);

  List<List<int>> zipped = [];
  for (int i = 0; i < args.length; i++) {
    if (i != args.length - 1) {
      List<int> newList = [];
      newList.add(args.elementAt(i));
      newList.add(args.elementAt(i + 1));
      zipped.add(newList);
    }
  }
  List<String> newList = [];
  for (List<int> zip in zipped) {
    newList.add(text.substring(zip.elementAt(0), zip.elementAt(1) - 1));
  }
  return newList;
}