I have a string “THURSDAY 26th JANUARY 2011”.
When I format this using CultureInfo.ToTitleCase():
var dateString = "THURSDAY 26th JANUARY 2011";
var titleString = myCultureInfoObject.TextInfo.ToTitleCase(dateString);
It is displayed like this: "Thursday 26Th January 2011". This is exactly what I need…except the T in 26Th has been capitalised. Is there any way to stop this from happening as it is a date and looks wrong? I.e only title-casing characters that don’t have a number directly before them?
You could use a regex with a
MatchEvaluatorto put only “real” words in title case:This will apply title case only to “THURSDAY” and “JANUARY”, but not “26TH” because it doesn’t match the regex pattern.