Swift – Convert a String to Lowercase

To convert a String to Lowercase in Swift, use String.lowercased() function. Call lowercased() function on the String. The function returns a new string with the contents of the original string transformed to lowercase alphabets.

The syntax to convert a String str to Lowercase is

str.lowercased()

lowercased() function returns a new String.

Example

In this example, we will take a string in variable str and convert this string to lowercase using String.lowercased() function.

main.swift

import Foundation

var str = "Hello World"
var result = str.lowercased()
print("Original  String : \(str)")
print("Lowercase String : \(result)")

Output

Original  String : Hello World
Lowercase String : hello world

Conclusion

In this Swift Tutorial, we learned how to convert a string to lowercase using String.lowercased() function.