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 lowercased()
In this tutorial, we will learn about the Swift String uppercased() method with the help of examples.
The lowercased() method converts all uppercase characters in a string into lowercase characters.
Example
var message = "SWIFT IS FUN"
// convert message to lowercased
print(message.lowercased())
// Output: swift is fun
lowercased() Syntax
The syntax of lowercased() method is:
string.lowercased()
Here, string is an object of the String class.
lowercased() Parameters
lowercased() method doesn't take any parameters.
lowercased() Return Value
returns the given string in lowercase
Example 1: Swift lowercased()
var string = "this should be lowercase!"
print(string.lowercased())
// string with numbers
// all alphabets should be lowercase
var string2 = "tH!S SH0uLd B3 UpP3rCas3!"
print(string2.lowercased())
Output
this should be lowercase! th!s sh0uld b3 upp3rcas3!
Example 2: Compare Two Strings Using lowercased()
// first string
var str1 = "swift is awesome!"
// second string
var str2 = "SwIfT Is AwEsOmE!"
// compare two strings
if(str1.lowercased() == str2.lowercased()) {
print("The strings are same.")
}
else {
print("The strings are not same.")
}
Output
The strings are same.
Did you find this article helpful?