はろー

まずは王道。
import std.stdio;

void main() {
	//write("hello world.\n");
	writeln("hello world.");
}
				
インポートせずに出力(object.dの自動import)。
void main() {
	printf("hello world.\0".ptr);
}
				
結合結合。
import std.stdio;

void main() {
writeln("h"~"e"~"l"~"l"~"o"~cast(char)0x20~"w"~"o"~"r"~"l"~"d"~".");
}
				
コマンドラインオプション取得で表示、 あと例外。
import std.stdio;

void main(string[] args) {
	try writeln(args[1]);
	catch(Exception) writeln(`hello world?`);
}
				
ファイル読み込んで出力。
msg.txt
1:hello world.[EOF]
import std.stdio;
import std.file;

void main() {
	auto buf = read("msg.txt".idup);
	writeln(buf);
}
				
配列とソート、配列長と集成体ループ、スライスと動的配列。
import std.stdio;

void main() {
	string[] list = [
		"5:lr", "4:ow", "2:ll",
		"3: o", "6:.d", "1:eh",
	];
	for(auto i=0; i < list.length; i++)
		list[i] = list[i][0..2]~list[i][3]~list[i][2];
	string hello;
	foreach(s; list.sort)
		hello ~= s[2..$];

	writeln(hello);
}
				
構造体、配列引数の糖衣構文とタプル。
import std.stdio;
import std.string;

struct HELLO {
	alias HELLO MyStruct;
	string first;
	string second;
	string third;

	static MyStruct opCall(string s) {
		MyStruct mys;
		with(mys) {
			first  = split(s, "-")[0];
			second = split(s, "-")[1];
			third  = split(s, "-")[2];
		}
		return mys;
	}
}
void main() {
	HELLO s = "HELLO- -WORLD.".tolower();
	writeln(s.tupleof);
}
				
クラスとかインターフェイスとか抽象化とかオーバーライドとか。
import std.stdio;
import std.uni;

interface IConverter {
	private string Big2Small(string);
}
abstract class CConverter: IConverter {
	private {
		string Big2Small(string s) {
			auto small = s.dup;

			foreach(i, c; s)
				if(isUniUpper(c)) small[i] = toUniLower(c);
			
			return small.idup;
		}
		string plus(string, string);
	}
}
class PlusPeriod: CConverter {
	private {
		string plus(string left, string right) {
			if(!right && !right.length)
			return left ~ ".";
			return left ~ right;
		}
		string s;
	}
	
	this(string s) {
		this.s = Big2Small(s);
	}
	override string toString() {
		return plus(s, null);
	}
}

void main() {
	writeln(new PlusPeriod("HELLo woRLd"));
}
				
hello world.
↑全部これ