{

Dart| Flutter How to: Convert String into an array


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

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

Convert String int 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('');
  print(st);
}

Output:

[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("");

  print(letterArray);
}

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(' ');
  print(st);
}

Output:

[welcome, john]
THE BEST NEWSLETTER ANYWHERE
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
Subscribe
You'll get a notification every time a post gets published here.





Related posts

Dart| Flutter How to: Read pubspec.yaml attributes (version) with examples

How to Create and build a Singleton Class Dart or Flutter example| Dart By Example

What is the difference between var and dynamic and final in dart?| Flutter By Example

How to: Check if Phone number is valid or not in Dart| Flutter By Example

Dart| Flutter How to read an image from a disk and resize a file

Dart/Flutter: How to write setter and getter fields or members variables in a class with Example

Dart| Flutter How to get extension name and MIME type of a file with example