Array Printing
Azi Hassan via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Sep 12 06:39:19 PDT 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.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
More information about the Digitalmars-d-learn
mailing list