BellevueCollege.Toolkit.TitleCase C# (CSharp) Метод

TitleCase() публичный статический Метод

Capitalizes the first letter of each word in a String
This method utilizes code taken from this forum post.
public static TitleCase ( string str ) : string
str string
Результат string
        public static string TitleCase(string str)
        {
            if(String.IsNullOrWhiteSpace(str)) {
                throw new ArgumentNullException("value");
            }

            StringBuilder result = new StringBuilder(str.ToLower());
            result[0] = char.ToUpper(result[0]);

            for( int i = 1; i < result.Length; ++i )
            {
                if( char.IsWhiteSpace(result[i - 1]) ) {
                    result[i] = char.ToUpper(result[i]);
                }
            }

            return result.ToString();
        }