Collection of library methods useful for scripting. https://dev.to/jessekphillips/parsing-a-string-in-d-15pk
void main() {
import std.file;
auto data = readText("filename.ext");
}
import std.algorithm;
auto data = "word word"
assert(data.startsWith("word"));
assert(data.endsWith("word"));
assert(data.skipOver("word"));
assert(data == " word");
import std.string;
auto data = " str ";
assert(data.strip == "str");
assert(data.stripLeft == " str");
assert(data.stripRight == "str ");
import std.algorithm;
auto haystack = "some long name";
auto needle = "long";
if(!haystack.find(needle).empty)
haystackHasNeedle(haystack);
import std.algorithm;
auto data = "one str\ntwo";
assert(data.splitter(" ").equal(
["one", "str\ntwo"]));
import std.array;
assert(data.split().equal(["one", "str", "two"]));
import std.range;
auto data = ["one", "two"];
auto head = data.front;
auto tail = data.dropOne;
auto content = ["post" , "tweet", "video", "talk"];
auto begin = content[0..2];
auto end = content[2..$];
// content is ["post" , "tweet", "video", "talk"];
// begin is ['post', 'tweet']
// end is ['video', 'talk']
import std.algorithm;
import std.typecons : tuple;
auto content = ["post" , "tweet", "video", "talk"];
content = content.remove(tuple(1,3));
assert(content.equal(["post" , "talk"]) );
import std.process;
import std.exception;
auto res = execute(["app name", "arg 1", "arg 2"]);
enforce(res.status == 0, "App exited with failure");
import std.stdio;
writeln(res.output);
import std.path;
buildNormalizedPath("foo/bar/../peas"
.absolutePath.expandTilde);
auto a = "foo";
auto b = "bar";
assert([a, b].joiner("/").equal(a.buildPath(b)));
assert("file.ext".extension == ".ext");
assert("file.ext".setExtension("gif") == "file.gif");
assert("file.ext".stripExtension == "file");
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.