Make first letter uppercase
Note: this entry has moved.
The traditional way of doing this is suming the difference between letter "A" and "a" to the first character. However, this will not work in internationalized scenarios. Here are the good reasons together with a great article on Unicode in general.
So I use the following approach, which is I18N-ready:
{
if ( name.Length <= 1) return name.ToUpper();
return Char.ToUpper( name[0] ).ToString() + name.Substring( 1 );
Char[] letters = name.ToCharArray();
letters[0] = Char.ToUpper( letters[0] );
return new string( letters );}
We don't need to pass the current culture to both String.ToUpper
and Char.ToUpper()
as they already do that internally.
Do you think there's a more efficient/cleaner way of doing this?