February 10, 2013 Line gaps with text files | ||||
|---|---|---|---|---|
| ||||
I'm using Windows and get gaps (blank lines) when using readText and std.stdio.write.
import std.stdio;
import std.file;
void main() {
string s = readText("s.txt");
writeln('[', s, ']');
File("s.txt", "w").write(s);
}
notepad.exe opens alright, (if you don't save as File(.., "wb")). But I'm having trouble with some others like GtkD. Also writeln always does it right.
| ||||
February 10, 2013 Re: Line gaps with text files | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Joel | This works better:
import std.stdio;
import std.file;
void main() {
//string s = readText("s.txt");
string s;
foreach(line; File("s.txt", "r").byLine()) {
s ~= line~"\r\n";
}
s = s[0..$-2];
writeln([s]);
File("s.txt", "w").write(s);
}
But one text file program says it has solitary carriage returns in it.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply