In my current project, I'm pulling data from a table that originates on a mainframe. Thus, the text is mostly ALL CAPS. Yuck.
My first thought for converting the data to proper case was to write a bunch of Substring calls. This seemed like a hack. My next thought was to use the VB strconv function, but since I'm writing this app in C#, I didn't want to commit the ultimate sin of including the Visual Basic namespace.
A quick google search came up TextInfo.ToTitleCase(). This looked promising, so I knocked together this code:
using System.Globalization;
public static string ToProperCase(string data) {
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(data);
}
Looks like it should work, right? I modified my app to use this new function, but lo and behold, the data was still ALL CAPS when it was displayed. WTF? I stepped through the code; I tried using the Command window; I surfed some more...nothing worked.
I finally snagged the code from this KB article. It worked. :-\ My frustration level was growing...I changed the “title” variable in the sample code so it was ALL CAPS, recompiled and ran the test app. It DIDN'T WORK! Aha...has something to do with ALL CAPS.
I ended up modifying my ToProperCase method:
using System.Globalization;
public static string ToProperCase(string data) {
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(data.ToLower());
}
This is my final, working solution. Seems bogus to me. Maybe one of these days I'll dive deeper into the issue.