lower case only first letter of word

codephantom me at noyb.com
Wed Dec 6 09:38:21 UTC 2017


On Tuesday, 5 December 2017 at 13:31:17 UTC, Marc wrote:
> Does D have a native function to capitalize only the first 
> letter of the word? (I'm asking that so I might avoid reinvent 
> the wheel, which I did sometimes in D)

// ----------------
module test;

import std.stdio;

void main()
{
     string myString = "heLlo WoRlD!";
     writeln( HereItIs(myString) );
}


string HereItIs(string someString)
{
     import std.uni : toLower;
     import std.ascii : toUpper;

     return (someString.ptr[0].toUpper ~  
someString[1..$].toLower);
}
// ------------------



More information about the Digitalmars-d-learn mailing list