www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Array Printing

reply Vino.B <vino.bheeman hotmail.com> writes:
Hi All,

  Request your help in printing the below array output as per the 
below required output

Array Output:
["C:\\Temp\\TEST2\\BACKUP\\dir1", "34", 
"C:\\Temp\\TEST2\\BACKUP\\dir2", "36", 
"C:\\Temp\\TEST3\\BACKUP\\dir1", "69"]
["C:\\Temp\\TEST2\\PROD_TEAM\\dir1", "34", 
"C:\\Temp\\TEST2\\PROD_TEAM\\DND1", "34"]
["C:\\Temp\\TEST2\\TEAM\\DND1", "34"]


Required output:
C:\Temp\TEST2\BACKUP\dir1			 	34
C:\Temp\TEST2\BACKUP\dir2 				36
C:\Temp\TEST3\BACKUP\\dir1 				69
C:\Temp\TEST2\PROD_TEAM\\dir1 			        34
C:\Temp\TEST2\PROD_TEAM\\DND1 			        34
C:\Temp\TEST2\TEAM\\DND1 	                        34

From,
Vino.B
Sep 11 2017
next sibling parent reply Anton Fediushin <fediushin.anton yandex.ru> writes:
On Tuesday, 12 September 2017 at 06:29:53 UTC, Vino.B wrote:
 Hi All,

  Request your help in printing the below array output as per 
 the below required output

 Array Output:
 ["C:\\Temp\\TEST2\\BACKUP\\dir1", "34", 
 "C:\\Temp\\TEST2\\BACKUP\\dir2", "36", 
 "C:\\Temp\\TEST3\\BACKUP\\dir1", "69"]
 ["C:\\Temp\\TEST2\\PROD_TEAM\\dir1", "34", 
 "C:\\Temp\\TEST2\\PROD_TEAM\\DND1", "34"]
 ["C:\\Temp\\TEST2\\TEAM\\DND1", "34"]


 Required output:
 C:\Temp\TEST2\BACKUP\dir1			 	34
 C:\Temp\TEST2\BACKUP\dir2 				36
 C:\Temp\TEST3\BACKUP\\dir1 				69
 C:\Temp\TEST2\PROD_TEAM\\dir1 			        34
 C:\Temp\TEST2\PROD_TEAM\\DND1 			        34
 C:\Temp\TEST2\TEAM\\DND1 	                        34

 From,
 Vino.B
Try this: writefln("%(%s\n%)", array); See std.format's documentation for more
Sep 12 2017
parent reply Vino.B <vino.bheeman hotmail.com> writes:
On Tuesday, 12 September 2017 at 07:28:00 UTC, Anton Fediushin 
wrote:
 On Tuesday, 12 September 2017 at 06:29:53 UTC, Vino.B wrote:
 Hi All,

  Request your help in printing the below array output as per 
 the below required output

 Array Output:
 ["C:\\Temp\\TEST2\\BACKUP\\dir1", "34", 
 "C:\\Temp\\TEST2\\BACKUP\\dir2", "36", 
 "C:\\Temp\\TEST3\\BACKUP\\dir1", "69"]
 ["C:\\Temp\\TEST2\\PROD_TEAM\\dir1", "34", 
 "C:\\Temp\\TEST2\\PROD_TEAM\\DND1", "34"]
 ["C:\\Temp\\TEST2\\TEAM\\DND1", "34"]


 Required output:
 C:\Temp\TEST2\BACKUP\dir1			 	34
 C:\Temp\TEST2\BACKUP\dir2 				36
 C:\Temp\TEST3\BACKUP\\dir1 				69
 C:\Temp\TEST2\PROD_TEAM\\dir1 			        34
 C:\Temp\TEST2\PROD_TEAM\\DND1 			        34
 C:\Temp\TEST2\TEAM\\DND1 	                        34

 From,
 Vino.B
Try this: writefln("%(%s\n%)", array); See std.format's documentation for more
Hi, Sorry, it didn't work, the genrated out is as below Output: "C:\Temp\TEST2\BACKUP\dir1" "34" "C:\Temp\TEST2\BACKUP\dir2" "36" "C:\Temp\TEST3\BACKUP\\dir1" "69" "C:\Temp\TEST2\PROD_TEAM\dir1" "34" "C:\Temp\TEST2\PROD_TEAM\DND1" "34" "C:\Temp\TEST2\TEAM\\DND1" "34" From, Vino.B
Sep 12 2017
parent Anton Fediushin <fediushin.anton yandex.ru> writes:
On Tuesday, 12 September 2017 at 13:15:01 UTC, Vino.B wrote:
 Hi,

  Sorry, it didn't work, the genrated out is as below
Oops, sorry. It should look like this: writefln("%-(%s\n%)", array);
Sep 12 2017
prev sibling next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 12 September 2017 at 06:29:53 UTC, Vino.B wrote:
  Request your help in printing the below array output as per 
 the below required output
You can just loop over it and write the components with the tab separator. Did you try that?
Sep 12 2017
prev sibling next sibling parent Azi Hassan <azi.hassan live.fr> writes:
On Tuesday, 12 September 2017 at 06:29:53 UTC, Vino.B wrote:
 Hi All,

  Request your help in printing the below array output as per 
 the below required output

 Array Output:
 ["C:\\Temp\\TEST2\\BACKUP\\dir1", "34", 
 "C:\\Temp\\TEST2\\BACKUP\\dir2", "36", 
 "C:\\Temp\\TEST3\\BACKUP\\dir1", "69"]
 ["C:\\Temp\\TEST2\\PROD_TEAM\\dir1", "34", 
 "C:\\Temp\\TEST2\\PROD_TEAM\\DND1", "34"]
 ["C:\\Temp\\TEST2\\TEAM\\DND1", "34"]


 Required output:
 C:\Temp\TEST2\BACKUP\dir1			 	34
 C:\Temp\TEST2\BACKUP\dir2 				36
 C:\Temp\TEST3\BACKUP\\dir1 				69
 C:\Temp\TEST2\PROD_TEAM\\dir1 			        34
 C:\Temp\TEST2\PROD_TEAM\\DND1 			        34
 C:\Temp\TEST2\TEAM\\DND1 	                        34

 From,
 Vino.B
You can also use leftJustifier (or the eager version, leftJustify) from std.string to make the output formatted like that : import std.stdio; import std.string; import std.range; void main() { auto a1 = ["C:\\Temp\\TEST2\\BACKUP\\dir1", "34", "C:\\Temp\\TEST2\\BACKUP\\dir2", "36", "C:\\Temp\\TEST3\\BACKUP\\dir1", "69"]; auto a2 = ["C:\\Temp\\TEST2\\PROD_TEAM\\dir1", "34", "C:\\Temp\\TEST2\\PROD_TEAM\\DND1", "34"]; auto a3 = ["C:\\Temp\\TEST2\\TEAM\\DND1", "34"]; a1.print; a2.print; a3.print; } void print(string[] array) { foreach(i; iota(0, array.length, 2)) writeln(array[i].leftJustifier(60, ' '), array[i + 1]); } Output : C:\Temp\TEST2\BACKUP\dir1 34 C:\Temp\TEST2\BACKUP\dir2 36 C:\Temp\TEST3\BACKUP\dir1 69 C:\Temp\TEST2\PROD_TEAM\dir1 34 C:\Temp\TEST2\PROD_TEAM\DND1 34 C:\Temp\TEST2\TEAM\DND1 34
Sep 12 2017
prev sibling parent reply lithium iodate <whatdoiknow doesntexist.net> writes:
On Tuesday, 12 September 2017 at 06:29:53 UTC, Vino.B wrote:
 Hi All,

  Request your help in printing the below array output as per 
 the below required output
As a fan of stuffing as much as possible into one line:
void main()
{   import std.stdio;
    import std.range;
    import std.algorithm.iteration;
    auto a = ["C:\\Temp\\TEST2\\BACKUP\\dir1", "34",
        "C:\\Temp\\TEST2\\BACKUP\\dir2", "36",
        "C:\\Temp\\TEST3\\BACKUP\\dir1", "69"];
    auto b = ["C:\\Temp\\TEST2\\PROD_TEAM\\dir1", "34",
        "C:\\Temp\\TEST2\\PROD_TEAM\\DND1", "34"];
    auto c = ["C:\\Temp\\TEST2\\TEAM\\DND1", "34"];
    chain(a, b, c).chunks(2).each!(e => writefln!"%-60s 
 %s"(e[0], e[1]));
}
Sep 12 2017
parent vino <vino_ss hotmail.com> writes:
On Tuesday, 12 September 2017 at 13:55:17 UTC, lithium iodate 
wrote:
 On Tuesday, 12 September 2017 at 06:29:53 UTC, Vino.B wrote:
 Hi All,

  Request your help in printing the below array output as per 
 the below required output
As a fan of stuffing as much as possible into one line:
void main()
{   import std.stdio;
    import std.range;
    import std.algorithm.iteration;
    auto a = ["C:\\Temp\\TEST2\\BACKUP\\dir1", "34",
        "C:\\Temp\\TEST2\\BACKUP\\dir2", "36",
        "C:\\Temp\\TEST3\\BACKUP\\dir1", "69"];
    auto b = ["C:\\Temp\\TEST2\\PROD_TEAM\\dir1", "34",
        "C:\\Temp\\TEST2\\PROD_TEAM\\DND1", "34"];
    auto c = ["C:\\Temp\\TEST2\\TEAM\\DND1", "34"];
    chain(a, b, c).chunks(2).each!(e => writefln!"%-60s 
 %s"(e[0], e[1]));
}
Hi, Thank you very much the one liner worked fine.
Sep 12 2017