Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Swift String uppercased()
In this tutorial, we will learn about the Swift String uppercased() method with the help of examples.
The uppercased() method converts all lowercase characters in a string into uppercase characters.
Example
var message = "swift is fun"
// convert message to uppercase
print(message.uppercased())
// Output: SWIFT IS FUN
uppercased() Syntax
The syntax of uppercased() method is:
string.uppercased()
Here, string is an object of the String class.
uppercased() Parameters
uppercased() method doesn't take any parameters.
uppercased() Return Value
returns the given string in uppercase.
Example 1: Swift uppercased()
var string = "this should be uppercase!"
print(string.uppercased())
// string with numbers
// all alphabets should be uppercase
var string2 = "Th!s Sh0uLd B3 uPp3rCas3!"
print(string2.uppercased())
Output
THIS SHOULD BE UPPERCASE! TH!S SH0ULD B3 UPP3RCAS3!
Example 2: Compare Two Strings Using uppercased()
// first string
var str1 = "swift is awesome!"
// second string
var str2 = "SwIfT Is AwEsOmE!"
// compare two strings
if(str1.uppercased() == str2.uppercased()) {
print("The strings are same.")
}
else {
print("The strings are not same.")
}
Output
The strings are same.
Did you find this article helpful?