Returns string with the first character converted to uppercase.


  1. Convert the first character of a string to uppercase:

    julia> ucfirst("hello")

    It converts the first character of the string "hello" to uppercase, resulting in "Hello".

  2. Handle empty strings:

    julia> ucfirst("")

    When the input string is empty, the function ucfirst returns an empty string.

  3. Preserve the case of the remaining characters:
    julia> ucfirst("JuLiA")

    The function only converts the first character to uppercase and leaves the remaining characters unchanged.

Common mistake example:

julia> ucfirst(123)
ERROR: MethodError: no method matching ucfirst(::Int64)

In this example, the input argument to ucfirst is an integer (123) instead of a string. The ucfirst function expects a string as input, so make sure to provide a valid string argument.

See Also

ascii, base64decode, Base64DecodePipe, base64encode, Base64EncodePipe, bin, bits, bytestring, charwidth, chomp, chop, chr2ind, contains, endswith, escape_string, graphemes, ind2chr, iscntrl, istext, isupper, isvalid, join, lcfirst, lowercase, lpad, lstrip, normalize_string, num2hex, parseip, randstring, readuntil, replace, repr, rpad, rsplit, rstrip, search, searchindex, split, startswith, string, stringmime, strip, strwidth, summary, takebuf_string, ucfirst, unescape_string, uppercase, utf16, utf32, utf8, wstring,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: