Convert all characters of a string to lowercase in Swift

This tutorial is all about converting all characters to lowercase in Swift. We will write a string in uppercase and then try to convert it into lowercase using lowercased() method.

lowercased() method

This method converts all the characters in a given string to lowercase. It does not take any parameters and returns the string that has all the characters converted into lowercase.

Here we will work on the implementation part of a string and its conversion into lowercase and compare two strings after converting into lowercase.

Convert a string into lowercase in Swift

As we know about lowercased() method now, it is time to know about its implementation.

We will declare a string and we will use the lowercased() inside the print function. The snippet part-

var str1="CODING IS FUN"
print(str1.lowercased())

Output-

coding is fun

Comparing two strings implementing lowercased()

Sometimes we need to work on two strings and compare them in the same case, if they are equal it should return True.

var str1="CODING IS FUN"
var str2="CODING IS fun"
print(str1.lowercased()==str2.lowercased())

Output-

true

This tutorial has some basic tutorials on the string and its implementation with its lowercased() module.

Leave a Reply

Your email address will not be published. Required fields are marked *