On Wednesday, 21 March 2018 at 11:30:28 UTC, Timoses wrote:
Hey,

I'm struggling to find a way to achieve this. I've looked through std.algorithm but didn't find anything.. Maybe I'm blind.

What I would like to do is filter out all spaces in a string and change the front letter to lower case:

https://xkcd.com/208/

unittest {
assert("my capitalized string".capitalize == "myCapitalizedString");
}

auto capitalize(string s) {
    import std.regex, std.uni;

    return s.replaceAll!(a => a[1].toUpper)(regex(" (.)"));
}

--
  Simen

Reply via email to