0

I want to take the string the lord of the rings and Title Case it to The Lord of the Rings.


However the built in .ToTitleCase() function capitalizes every word. The Lord Of The Rings.

I want to use the English rules here and Lower Case of and the and other conjunctions.

https://english.stackexchange.com/a/34


C#

string title = "the lord of the rings";

TextInfo textinfo = new CultureInfo("en-US", false).TextInfo;
title = textinfo.ToTitleCase(title);

http://rextester.com/KDOOG71862

Matt McManis
  • 4,475
  • 5
  • 38
  • 93
  • 3
    It is not supported in .NET, so you will have to write your own method (or find some package on the web). – Jeppe Stig Nielsen Apr 12 '18 at 07:28
  • 2
    You will have to 1st find a set of rules and then write a function that implements it. The latter is rather simple but the 1st is not. I find the answers in the link all wrong by my standards; e.g.: Nobody even mentions 'verbal expressions' which consist of a verb and a prepostion that alters the meaning of the verb and therefore should be capitalized. This is hard to implement, though, e.g.: 'Working On a Building' but 'Standing on the Moon'. – TaW Apr 12 '18 at 07:36
  • @Wikto: You beat me to it. Wow, I had completely forgotten I had posted my code before, thanks a lot for pointing it out -. I have appended the current version.. – TaW Apr 12 '18 at 07:48

0 Answers0