Split String by Comma
To split a given string by comma separator in Dart, call split() method on the string, and pass comma ','
as argument to split() method. split() method returns the split parts as a list.
Dart Program
In the following program, we take a string with values separated by comma, and split this string by comma character.
main.dart
void main() { var myString = 'apple,banana,cherry'; var output = myString.split(','); print(output); }
Output
[apple, banana, cherry]
Conclusion
In this Dart Tutorial, we learned how to split a string by comma separator in Dart using String.split() method.