How can i make the first letter of a string uppercase?
i know this is trivial but can someone help me out. thanks.
# 1 Re: How can i make the first letter of a string uppercase?
string hw = "hello world";
string properCase = Strings.StrConv(hw, VbStrConv.ProperCase, 0); // Hello World
string firstUpper = hw[0].ToString().ToUpper() + hw.Substring(1, hw.Length - 1); // Hello world
# 2 Re: How can i make the first letter of a string uppercase?
Strings.StrConv is perfect method to do that. However, you have to add Microsoft.VisualBasic into C# project as reference. Does it worth?
Or maybe just loop thru the string and convert the letter to uppercase if there is whitespace before it, then convert the first letter to upper case.
# 3 Re: How can i make the first letter of a string uppercase?
This will work but is not really all that elegant.
string s = "todd";
s = s.Substring(0, 1).ToUpper() + s.Substring(1)