digitalmars.D.learn - 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.
Feb 09 2013
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.
Feb 09 2013