What is the string.split() method in dart?
The split() method is a built-in method of the string in Dart. It divides the long string into a list of smaller sub-strings based on a delimiter/ keyword. Splitting can be useful when working with CSV files.
It returns a list of sub-strings. It divides the original long string based on the delimiter. In other words, a sub-string is inserted into a list wherever a delimiter is found.
Syntax
The following is the syntax of the split() method in dart.
string.split(delimiter)
delimiteris a string or character by which we divide the original string into a list of smaller sub-strings.
Example
The following example will demonstrate how we use split a list using the split() method.
import 'dart:convert';void main() {var str='Welcome to Educative Answers';var list=str.split(' ');print(list);}
Explanation
Line 4: We declare an
strvariable that stores the original string, which divides into sub-strings.Line 5: We call the
split()method ofstrand pass the' '(space) as the delimiter. We store the result in a var namedlist.Line 7: We print the
liston the console.
Free Resources