load data from txt file
visitor
visitor at gmail.com
Tue Jan 2 23:25:21 UTC 2018
On Tuesday, 2 January 2018 at 22:08:52 UTC, aerto wrote:
> Hello and happy new year im new in d so i have a question
>
> writeln(data["admin"]); // i want this to print 123456789
> writeln(data["test"]); // i want this to print test345
if you can rewrite your users.txt file like so :
["admin":"123456789",
"test":"test345"]
with the help of import expression /-J command line switch (or
dub stringImportPaths)
https://dlang.org/spec/expression.html#import_expressions
"dmd -release -J. yourfile.d" for example if users.txt is in same
folder
import std.stdio;
string[string] data;
static this() {
// of course you could also do this in main()
data = mixin(import("users.txt"));
}
void main(string[] args)
{
writefln("test => %s", data["test"]);
}
More information about the Digitalmars-d
mailing list