write to file array by lines

wobbles via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 15 06:16:30 PDT 2016


On Tuesday, 15 March 2016 at 12:55:17 UTC, Suliman wrote:
> I created better example to show.
>
> string [] myarr = ["foo", "bar", "baz"];
> myarr ~= "new";
> File file = File(`result.txt`, "w");
> file.write(myarr);
>
> is any way to write myarr to file in byLine mode

  void main(){
      import std.stdio;
      import std.ascii;
      import std.algorithm;

      string[] myArr = ["foo", "bar", "baz"];
      myArr ~= "new";
      writeln("=== each! ===");
      myArr.each!(a => writeln(a));
      writeln("=== Using format ===");
      writefln("%-(%s\n%)", myArr);

      writeln("=== Using joiner ===");
      myArr.joiner(std.ascii.newline).writeln;
  }


Output:
=== each! ===
foo
bar
baz
new
=== Using format ===
foo
bar
baz
new
=== Using joiner ===
foo
bar
baz
new



More information about the Digitalmars-d mailing list