ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Stuart Sillitoe

Emulation of PHPs ucfirst()

Source

public static string UcFirst(this string theString)
{
    if ( string.IsNullOrEmpty(theString) )
    {
        return string.Empty;
    }

    char[] theChars = theString.ToCharArray();
    theChars[0] = char.ToUpper(theChars[0]);

    return new string(theChars);

}

Example

"some string".UcFirst();

OR

string str = "a string";

str.UcFirst();

Author: Stuart Sillitoe

Submitted on: 1 jun. 2016

Language: C#

Type: String

Views: 4124