D Language Strings Reversing a string


Example

string is defined as alias string = immutable(char)[];: so need to use dup to make a mutable char array, before it can be reversed:

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;

}