How to use tolower in D

A.F*_*zen 2 d phobos

I want to to put the first letter of a string into lowercase in D.

As a string is imutable in D, there doesn't seem to be a simple way.

I came up with this:

string mystr = "BookRef";
string outval = toLower( mystr[0..1] ) ~ mystr[1..$]; 
writeln( "my outval: ", outval );
Run Code Online (Sandbox Code Playgroud)

Is there an easier way ?

gre*_*ify 6

为了参考和完整性,您可以通过链接范围来构建它而无需任何分配。使用空字符串还具有其他优点:

auto downcase(string w)
{
    import std.range, std.uni;
    return w.take(1).asLowerCase.chain(w.drop(1));
}
Run Code Online (Sandbox Code Playgroud)

在run.dlang.io上在线尝试