Possible Duplicate:
How to capitalize first letter of each sentence?
public static string CapitalizeEachWord(this string sentence)
{
string[] words = sentence.Split();
foreach (string word in words)
{
word[0] = ((string)word[0]).ToUpper();
}
}
I'm trying to create a extension method for a helper class I'm trying to create for myself for future projects.
This one particular is supposed to capitalize each word appropriately. Meaning, the first letter of every word should be capitalized. I'm having trouble getting this to work.
It says I cannot convert a char to a string, but I remember being able to do that at some point. Maybe I'm forgetting a crucial part.
Thanks for the suggestions.
Maybe use the
ToTitleCase
method in theTextInfo
classHow to convert strings to lower, upper, or title (proper) case by using Visual C#
Here's how I do it:
Try this: