4

This is a standard way to title case uppercase names using the .NET Humanizer library.

"FIRST M HYPHENATED-LAST".Transform(To.LowerCase, To.TitleCase);
// Result (v1.37.0): "First M Hyphenated-last"
// Desired Result: "First M Hyphenated-Last"

Unfortunately the character following the hyphen is lowercase when it seems to me it should be uppercase.

Anyone have any suggestions for getting the result I'm looking for with Humanizer, or is this just not possible with Humanizer as of v1.37.0?

Jeremy Cook
  • 20,840
  • 9
  • 71
  • 77
  • I have no idea about Humanizer, but would it be lot of work to split - transform - join ? – Arghya C Sep 29 '15 at 21:08
  • @ArghyaC no not too much work. I just use humanizer for so many things and overall it works great and is so convenient. This is the first case I've ran into where it misses the mark, and I was hoping there is a technique I'm not aware of that will produce the desired result. If not, I'll do it myself like you suggest, and may look into issuing a pull-request to the project. – Jeremy Cook Sep 29 '15 at 21:32
  • I just had a look at `Humanizer` and it looked good. But couldn't find something which can solve problem like yours without a `Split()` or `Replace()`. If you pull and add couple of method that accepts some chars that are allowed, would be helpful for others. Something like `Humanize(this string s, params char[] allowedChars)` – Arghya C Sep 29 '15 at 22:04
  • +1 for introducing me to this library. Seems interesting. Does `xxx.Humanize(LetterCasing.Title)` not work? – Frank Fajardo Sep 29 '15 at 22:41
  • I just saw the code, and my suggestion would not work. :( – Frank Fajardo Sep 29 '15 at 22:46

1 Answers1

1

Try this:

var name = "FIRST M HYPHENATED-LAST";
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cultureInfo.TextInfo;
var result = textInfo.ToTitleCase(name.ToLower());
Console.WriteLine(result);
Darlan Dieterich
  • 2,369
  • 1
  • 27
  • 37