How to iterate over a String, char by char, in Dart?

You could also use the split method to generate a List of characters.

input.split('').forEach((ch) => print(ch));

Unfortunately strings are currently not iterable so you would have to use a for loop like this

for(int i=0; i<s.length; i++) {
  var char = s[i];
}

Note that Dart does not have a character class so string[index] will return another string.


An alternative implementation (working with characters outside the basic multilingual plane):

"A string".runes.forEach((int rune) {
  var character=new String.fromCharCode(rune);
  print(character);
});