Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to cast a String to char[] in Dart

How to convert a String to an array of char in Dart ?

I’ve tried to cast a String to a List of char and it didn’t work

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Loop through the string, and assign each character to the end of a List. Please mark my answer as accepted. Code is given below:

void main() {
  String str = 'This is a string.';
  List charStr = [];
  
  for(var i=0; i<str.length; i++ ) {
    charStr.add(str[i]);
  }
  
  print(charStr);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading