split function

List<String> split(
  1. String string,
  2. String separator, {
  3. int max = 0,
})

Implementation

List<String> split(String string, String separator, {int max = 0}) {
  //var result1 =  List<String>();
  var result =  <String>[];

  if (separator.isEmpty) {
    result.add(string);
    return result;
  }

  while (true) {
    var index = string.indexOf(separator, 0);
    if (index == -1 || (max > 0 && result.length >= max)) {
      result.add(string);
      break;
    }

    result.add(string.substring(0, index));
    string = string.substring(index + separator.length);
  }

  return result;
}