uppercase
uppercase(string)
Returns string
with all characters converted to uppercase.
Examples
In the Julia programming language, the function uppercase(string)
Returns string
with all characters converted to uppercase.
julia> uppercase("hello world")
"HELLO WORLD"
Provide common examples of its use. If there are any common mistakes users make, add an example.
-
Convert a string to uppercase:
julia> uppercase("julia programming") "JULIA PROGRAMMING"
This example converts the given string to uppercase.
-
Handle empty strings:
julia> uppercase("") ""
It correctly handles the case when an empty string is provided as input.
- Convert individual words to uppercase in a sentence:
julia> sentence = "the quick brown fox" julia> words = split(sentence) julia> uppercase.(words) 4-element Array{String,1}: "THE" "QUICK" "BROWN" "FOX"
Here, the
uppercase
function is used in combination with broadcasting (.
) to convert each word in a sentence to uppercase.
Common mistake example:
julia> uppercase(42)
ERROR: MethodError: no method matching uppercase(::Int64)
In this example, the input provided is not a string, causing a MethodError
. It's important to ensure that the input to uppercase
is a valid string type to avoid such errors.
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.