Manipulate slice or specific element of range and return range
Simen Kjærås
simen.kjaras at gmail.com
Wed Mar 21 12:07:49 UTC 2018
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
More information about the Digitalmars-d-learn
mailing list