Swift String lowercased()

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.