ucfirst
ucfirst(string)
Returns string
with the first character converted to uppercase.
Examples
-
Convert the first character of a string to uppercase:
julia> ucfirst("hello") "Hello"
It converts the first character of the string
"hello"
to uppercase, resulting in"Hello"
. -
Handle empty strings:
julia> ucfirst("") ""
When the input string is empty, the function
ucfirst
returns an empty string. - Preserve the case of the remaining characters:
julia> ucfirst("JuLiA") "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.