split method
Reads file
as a string and splits it into parts, slicing the string
at each occurrence of any of the splitters
. file
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
Future<List<String>> split({
required List<String> splitters,
List<Object>? delimiters,
bool removeSplitters = true,
bool trimParts = false,
Encoding encoding = utf8,
}) async {
assert(await exists(), 'File doesn\'t exist.');
assert(splitters.isNotEmpty);
assert(delimiters == null ||
delimiters.every(
(delimiter) => delimiter is String || delimiter is Delimiter));
return StringSplitterIo.split(
this,
splitters: splitters,
delimiters: delimiters,
removeSplitters: removeSplitters,
trimParts: trimParts,
encoding: encoding,
);
}