Discussion:
[dart-misc] Hi to delete from existing dart file
ibrahim shehu ibrahim
2018-11-21 11:17:34 UTC
Permalink
Hi 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 an email to misc+***@dartlang.org.
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
2018-11-21 19:37:38 UTC
Permalink
Well, 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
fix that:

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 ibrahim
Hi 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 an
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 an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CADK_2AUhry1VpNrSAKgNyROrpVGo-OR9wJMOXqhpTZwAOT7JUg%40mail.gmail.com.
'Lasse R.H. Nielsen' via Dart Misc
2018-11-22 15:45:11 UTC
Permalink
Nice 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 Bang
Well, 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 ibrahim
Hi 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 an
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 an
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>
.
--
Lasse R.H. Nielsen - ***@google.com
'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 email to misc+***@dartlang.org.
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.
ibrahim shehu ibrahim
2018-11-22 15:53:32 UTC
Permalink
Okay thank you how do I tell the dart the location of my text file

On Thu, 22 Nov 2018, 4:45 pm 'Lasse R.H. Nielsen' via Dart Misc <
Post by 'Lasse R.H. Nielsen' via Dart Misc
Nice 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 Bang
Well, 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 ibrahim
Hi 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 an
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>
.
--
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 email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CADe%2ByE3RLbgBgkyemP22CVVw_9UzJqVjqS4q%3DzRo6XJS1%2BJy_g%40mail.gmail.com.
David Liedle
2018-11-26 09:12:19 UTC
Permalink
The path to the text file will depend entirely upon the location of the
Dart code when it runs. For example, if you have `file.txt` located at
`/home/myuser/Desktop/file.txt` and you execute `dart testfile.dart` from
`/home/myuser/bin/testfile.dart`, you would need to specify a path relative
to that with `../Desktop/file.txt` for a relative reference, or the
absolute path `/home/myuser/Desktop/file.txt` so it would not matter where
you're "at" when you run. Those are *nixy examples, but adjust for Mac or
Windows accordingly. If you are running the Dart script in the same
directory as the file, you can omit any path reference and just refer to
the file by its filename.

*David Christian Liedle*

Call/Text : +1 (323) 4-LIEDLE
HelloFax : +1 (323) 430-8886
Website : http://davidcanhelp.me/

Skype : davidchristianliedle


Snail Mail:

1820 Avenue M #623

Brooklyn, NY 11230
USA



On Thu, Nov 22, 2018 at 10:53 AM ibrahim shehu ibrahim <
Post by ibrahim shehu ibrahim
Okay thank you how do I tell the dart the location of my text file
On Thu, 22 Nov 2018, 4:45 pm 'Lasse R.H. Nielsen' via Dart Misc <
Post by 'Lasse R.H. Nielsen' via Dart Misc
Nice 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 Bang
Well, 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 ibrahim
Hi 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>
.
--
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/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>
.
--
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 email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CAMK_ixoagjL8h_x9mT9Ghw57OCrSLn0uRJWn7VFWDymmPiprjw%40mail.gmail.com.
Continue reading on narkive:
Loading...