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.
The following is the syntax of the split()
method in dart.
string.split(delimiter)
delimiter
is a string or character by which we divide the original string into a list of smaller sub-strings.
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);}
Line 4: We declare an str
variable that stores the original string, which divides into sub-strings.
Line 5: We call the split()
method of str
and pass the ' '
(space) as the delimiter. We store the result in a var named list
.
Line 7: We print the list
on the console.
Free Resources