Titleize changes non alphabetic elements of a string
I need to write a common DateTime interval pattern: "dayname, daynumber month, hours:minutes - hours:minutes". It should work with all languages.
I start with this:
string interval = dateTimeBegin.ToString ("ddddddddd, dd MMM, HH:mm - ", App.CultureSettings) + dateTimeEnd.ToString ("HH:mm", App.CultureSettings);
The result is this kind of string:
"mercoledì, 25 feb, 14:30 - 15:30"
In some culture settings the days and the months are not capitalized by default, but I need them capitalized, so I use Humanize .Titleize method:
interval = interval.Titleize();
But the resulting string is:
"Mercoledì 25 Feb 14 30 15 30"
While I was expecting:
"Mercoledì, 25 Feb, 14:30 - 15:30"
Is this a bug or by design? And if the latter, is there a way for preventing Titleize to mess with non alphabetic characters? Or maybe a way to humanize a datetime interval with days and months capitalized? Something like:
string interval = Humanize.TimeInterval(dateTimeStart, dateTimeBegin, forcetitlecaps: true);
Thank you in advance!
I think that's by design. The Titleize method uses the Humanize extension internally, and this method strips a lot of non-word characters in order to make texts more readable. If you only want to change the case, then interval.ApplyCase(LetterCasing.Title) might be a better match for you.