split static method

List<String> split(
  1. String string, {
  2. required List<String> splitters,
  3. List<Object>? delimiters,
  4. bool removeSplitters = true,
  5. bool trimParts = false,
})

Splits string into parts, slicing the string at each occurrence of any of the splitters. string must not be null, splitters must not be null or empty.

Note: If using a linebreak (\n) as a splitter, it's a good idea to include \r\n before \n, as Windows and various internet protocols will automatically replace linebreaks with \r\n for backwards compatibility with legacy platforms. Not doing so shouldn't cause any problems in most cases, but will leave strings with a hidden \r character. \n\r is also used as a line ending by some systems.

delimiters can be provided as Strings and/or Delimiters to denote blocks of text that shouldn't be parsed for splitters.

If removeSplitters is true, each string part will be captured without the splitting character(s), if false, the splitter will be included with the part. removeSplitters must not be null.

If trimParts is true, the parser will trim the whitespace around each part when they are captured. trimParts must not be null.

Implementation

static List<String> split(
  String string, {
  required List<String> splitters,
  List<Object>? delimiters,
  bool removeSplitters = true,
  bool trimParts = false,
}) {
  assert(splitters.isNotEmpty);
  assert(delimiters == null ||
      delimiters.every(
          (delimiter) => delimiter is String || delimiter is Delimiter));

  return StringSplitterConverter(
    splitters: splitters,
    delimiters: delimiters,
    removeSplitters: removeSplitters,
    trimParts: trimParts,
  ).convert(string);
}