Posted by: jorgedbucaran on: February 9, 2008
Unfortunately there is no String::ToProperCase() in the .NET Framework, but there is TextInfo::ToTitleCase which is not that bad and actually provides international support. Can’t help a chuckle from that statement. However, if you don’t like:
TextInfo ^texti = gcnew CultureInfo("en-US", false)->TextInfoYou can always implement your own simplified version. I share mine here:
String ^toTitleCase(String ^string)
{
Text::StringBuilder ^stringb = gcnew Text::StringBuilder();
Char lastch = ' ';
for each (Char ch in string) {
if (Char::IsLetter(ch) && Char::IsWhiteSpace(lastch)) {
ch = Char::ToUpper(ch);
}
lastch = ch;
stringb->Append(ch);
}
return stringb->ToString();
}