反轉一個字串

string 定義為 alias string = immutable(char)[];:所以需要使用 dup 來製作一個可變的 char 陣列,然後才能反轉:

import std.stdio;
import std.string;

int main() {

    string x = "Hello world!";
    char[] x_rev = x.dup.reverse;
    
    writeln(x_rev); // !dlrow olleH
    
    return 0;

}