digitalmars.D.learn - Array Printing
- Vino.B (19/19) Sep 11 2017 Hi All,
- Anton Fediushin (4/23) Sep 12 2017 Try this:
- Vino.B (19/47) Sep 12 2017 Hi,
- Anton Fediushin (3/5) Sep 12 2017 Oops, sorry. It should look like this:
- Adam D. Ruppe (3/5) Sep 12 2017 You can just loop over it and write the components with the tab
- Azi Hassan (31/50) Sep 12 2017 You can also use leftJustifier (or the eager version,
- lithium iodate (2/18) Sep 12 2017
- vino (4/23) Sep 12 2017 Hi,
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
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.BTry this: writefln("%(%s\n%)", array); See std.format's documentation for more
Sep 12 2017
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, 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.BHi 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.BTry this: writefln("%(%s\n%)", array); See std.format's documentation for more
Sep 12 2017
On Tuesday, 12 September 2017 at 13:15:01 UTC, Vino.B wrote:Hi, Sorry, it didn't work, the genrated out is as belowOops, sorry. It should look like this: writefln("%-(%s\n%)", array);
Sep 12 2017
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 outputYou can just loop over it and write the components with the tab separator. Did you try that?
Sep 12 2017
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.BYou 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
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 outputAs 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
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, Thank you very much the one liner worked fine.Hi All, Request your help in printing the below array output as per the below required outputAs 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