如何按行迭代字符串内容(分隔符为回车符)

The method readAsString() returns the whole content in one string.

例如,这是一个源文件:

#line1 // note, the carriage return here (new line symbol)
#line2

如何按行迭代内容,即像源文件中那样用行分隔内容?

await file.readAsString().then(
    (value) {
      print(value); // the whole content will be printed

      // how to iterate the content by lines
      // i.e. process at first `#line1` and so on
    },
);
评论
et_ea
et_ea

Use File.readAsLines:

await file.readAsLines().then(
    (List<String> lines) {
      for (var line in lines) {
        ...
      }
    },
);
点赞
评论