Daniel Cazzulino's Blog : Make first letter uppercase

Make first letter uppercase

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:

private string MakeFirstUpperMakePascalCase( string name )
{
        if ( name.Length 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?

posted on Friday, January 09, 2004 10:07 AM by kzu

What do you think?

(required) 
required 
optional
required