On Thu, 22 Nov 2018, 4:45 pm 'Lasse R.H. Nielsen' via Dart Misc <
Post by 'Lasse R.H. Nielsen' via Dart MiscNice code!
As a nitpick, I'll just make my usual pitch for using `forEach` on
streams instead of `listen` unless you *need* the subscription.
import 'dart:convert';
import 'dart:io';
main() {
IOSink newFile = File("file_replaced.txt").openWrite();
File("file.txt")
.openRead()
.transform(utf8.decoder)
.transform(LineSplitter())
.forEach((String line) {
if (!line.startsWith("n")) {
newFile.writeln(line);
}
})
.whenComplete(newFile.close);
}
I know I'm just tilting at windmills, but I think forEach is
under-appreciated! :)
/L
Post by Jacob BangWell, you can do something like this (I have assumed you file is UTF-8
encoded). Also, the line ending of the file is always converted to /n so if
it is important that you have a specific line ending style then you need to
import 'dart:convert';
import 'dart:io';
main() {
IOSink newFile = new File("file_replaced.txt").openWrite();
new File("file.txt")
.openRead()
.transform(utf8.decoder)
.transform(new LineSplitter())
.listen((String line) {
if (!line.startsWith("n")) {
newFile.writeln(line);
}
}, onDone: () {
newFile.close();
});
}
Den ons. 21. nov. 2018 kl. 16.03 skrev ibrahim shehu ibrahim <
Post by ibrahim shehu ibrahimHi guys please can anybody help me with the source code in dart,i want
to write a program that will read from an existing text file such that it
will delete any line that doesn't begin with letter "n" ,do that till the
end of the file..thanks
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google
Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send
To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/8cfff465-127e-42b0-aaee-f932faabb0ed%40dartlang.org
.
--
Jacob Bang / julemand101
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google
Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send
To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/CADK_2AUhry1VpNrSAKgNyROrpVGo-OR9wJMOXqhpTZwAOT7JUg%40mail.gmail.com
<https://groups.google.com/a/dartlang.org/d/msgid/misc/CADK_2AUhry1VpNrSAKgNyROrpVGo-OR9wJMOXqhpTZwAOT7JUg%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
--
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 KÞbenhavn K
- Denmark - CVR nr. 28 86 69 84
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/CA%2BeWuVCtzUN0BL_kwf%2BMpCmozRwr_y9zNtYZ0NzpmKiFuo5zPQ%40mail.gmail.com
<https://groups.google.com/a/dartlang.org/d/msgid/misc/CA%2BeWuVCtzUN0BL_kwf%2BMpCmozRwr_y9zNtYZ0NzpmKiFuo5zPQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
"Dart Misc" group.
https://groups.google.com/a/dartlang.org/d/msgid/misc/CADe%2ByE3RLbgBgkyemP22CVVw_9UzJqVjqS4q%3DzRo6XJS1%2BJy_g%40mail.gmail.com
<https://groups.google.com/a/dartlang.org/d/msgid/misc/CADe%2ByE3RLbgBgkyemP22CVVw_9UzJqVjqS4q%3DzRo6XJS1%2BJy_g%40mail.gmail.com?utm_medium=email&utm_source=footer>
.