Dart| Flutter How to: Convert String into an array

How to Convert String into an array Dart and Flutter

This tutorial shows multiple ways to convert a String into an array or list in dart and flutter programming.

  • Split the string into a list of characters using the String.split() method
  • remove whitespaces using the trim method, and split using split() method

Since Array does not support Dart. We will show you to convert to List only.

Convert String into a list of characters List or Array of character

String.split() method split the string with the delimiter. The default delimiter is an empty character.

Here is an example Convert String into a List of string characters

void main() {
  var str="welcome";
  List<String> st=str.split('');


[w, e, l, c, o, m, e]

You can also use trim the string and split the string

void main() {
  var str="welcome john";
  List<String> letterArray = str.trim().split("");


Split String int0 words in dart

Here is an example Convert String int List of substrings with blank space delimiter.

void main() {
  var str="welcome john";
  List<String> st=str.split(' ');


[welcome, john]
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.

Related posts

Perl How to: Find a Given Variable String is numeric or not

Dart/Flutter: Check if String is Empty, Null, or Blank example

How to generate Unique Id UUID in Dart or Flutter Programming| Dart or Flutterby Example

How to Sort List of numbers or String in ascending and descending in Dart or Flutter example

Dart Enum comparison operator| Enum compareByIndex example| Flutter By Example

Dart Example - Program to check Leap year or not

Dart Example to count the number of digits in a number| Decimals Count in Dart