Remove unwanted ' \r ' from an Array ... by reading a *.txt file.

Mil58 peter_pinkness at yahoo.fr
Thu Oct 24 15:27:05 UTC 2019


Hi all It's me again ;-)
(because you're very strong in Dlang, here...)
In want a result as i write in a comment, with remove unwanted 
'\r' >>

import std.stdio;
import std.file;
import std.conv;
import std.process : executeShell;

/* Content of 'values.txt' >>
    abcd
    1234
    03b52h
*/

void main() {
	auto fichier = File("values.txt", "r+");
	string[] buffer;
   foreach (line ; File("values.txt").byLine)
     buffer ~= line.to!string;

   writeln(buffer);
   // Result: ["abcd\r", "1234\r", "03b52h"]

   writeln(buffer[0], " - ", buffer[1], " - ", buffer[2]);
   // Result:  - 03b52h    :-(

   // Instead, i would :  abcd - 1234 - 03b52h  !!!

executeShell("pause");
fichier.close();
}

Thanks a lot, by advance :-)




More information about the Digitalmars-d-learn mailing list