TitleCase vs PascalCase (sort of)

Note: this entry has moved.

A reader suggested I should use TextInfo.ToTitleCase method to turn the first of a string letter into uppercase. However, title case is a different thing from PascalCase. The former converts the first letter of each word into uppercase, and the rest to lowercase. So, for the one asking for a prize to Panos it won't come from me :p. Here's what you get from the ToTitleCase method:
// Writes "Hello World"
Console.WriteLine(CultureInfo.CurrentCulture.TextInfo.ToTitleCase("hello world"));

// Writes "Helloworld". Ups!
Console.WriteLine(CultureInfo.CurrentCulture.TextInfo.ToTitleCase("helloWorld"));
The problem is that there's no word boundary in a camelCase code indentitier (be it a variable name, an XML element name, and so on). Therefore, the approach is flawed. So far, I still prefer my initial approach.

Anyone else that wants to win the prize? ;)

No Comments