Creating Struct for an output of a program.
Vino
vino.bheeman at hotmail.com
Tue Jan 9 07:57:19 UTC 2018
Hi All,
Request your help on how to create a struct with the output of
the below program.
Program:
import std.algorithm: all, map, filter;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.container.array;
import std.string: split, strip;
import std.uni: isWhite, toLower;
import std.range: chunks;
void main () {
Array!string TableData, StructureData;
auto Meta =
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\meta\\meta.txt", "r");
auto MetaData = Array!(Tuple!(string, string))(Meta.byLineCopy()
.filter!(line => !line.all!isWhite)
.map!(a => a.split(":"))
.map!(a => tuple(a[0].toLower.strip, a[1].toLower.strip)));
foreach (line; MetaData[]) { TableData.insertBack(line[0]);
StructureData.insertBack(line[1]); }
for(int i = 0; i < TableData[].length; i++ ) {
auto S1 = StructureData[i].split(",").chunks(3);
auto S2 = S1.map!(a => tuple(a[0],a[1],a[2]));
for(int z =0; z < S2.length; z++)
{ writefln("%-8s %;s", S2[z][1] , S2[z][0]); }
}
}
Output:
string name;
string country;
int age;
Need to create as struct using the output
struct Layout {
{
string name;
string country;
int age;
}
From,
Vino.B
More information about the Digitalmars-d-learn
mailing list