Dart Split String

Welcome tutorial on Split String on Dart.

You can split a string with a substring as delimiter using String.split() method.

The syntax of split() method is:

split(Pattern pattern)

The function returns a list of strings.

Example – Split String in Dart

In this example, we will take a string with words separated by delimiter -. And then split it into array of words using split() method.

Dart Program

void main(){
	
	String str = 'hello-world-tutorialkart';
	
	//split string
	var arr = str.split('-');
	
	print(arr);
}

Output

[hello, world, tutorialkart]

Example – Split String in Dart

In this example, we will take a string with words separated by delimiter abc. The delimiter is ripped off from the string and the parts are returned as list.

Dart Program

void main(){
	
	String str = 'helloabcworldabctutorialkart';
	
	//split string
	var arr = str.split('abc');
	
	print(arr);
}

Output

[hello, world, tutorialkart]

Example – Split Comma Sepatared String in Dart

In this example, we will take a string of comma separated values. We shall split this CSV string into list of values.

Dart Program

void main(){
	
	String str = '25,85,96,741,63';
	
	//split string
	var arr = str.split(',');
	
	print(arr);
}

Output

[25, 85, 96, 741, 63]

Conclusion

In this Dart Tutorial, we learned how to split a string in Dart with delimiter substring using String.split() method.