Split String by Space

To split a given string by single space as separator in Dart, call split() method on the string, and pass single space ' ' 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 single space character, and split this string by using split() method.

main.dart

</>
Copy
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 single space separator, using String.split() method.