How to match each character in a string in Dart?

I donโ€™t see Dart lines being treated as lists of characters. I guess I should use for loops that would be lame.

+4
source share
2 answers

Alternative implementation (work with characters outside the base multilingual plane):

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

Unfortunately, strings are not iterable at the moment, so you 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 the string [index] will return another string.

+3
source

Source: https://habr.com/ru/post/1396541/


All Articles