The toLowerCase
method converts all the characters in a string to lowercase and returns the converted string as a result. However, it doesn’t change the actual string.
Note: If the string is already in lowercase, then the string is returned as it is.
String toLowerCase()
This method doesn’t take any arguments.
This method converts all the characters present in the current string to lowercase and returns it.
The code given below shows us how to use the toLowerCase
method:
void main() {// create a empty stringvar str = "TeST";print('The string is - $str.');// Convert the string to lowercaseprint("str.toLowerCase() : ${str.toLowerCase()}");str = "HeLLO";print('\nThe string is - $str.');// Convert the string to lowercaseprint("str.toLowerCase() : ${str.toLowerCase()}");}
In the code above:
In line 3, we create a variable with the name str
and assign a "TeST"
string as a value.
In line 7, we use the toLowerCase
method to convert the str
to a string with lowercase characters only. The toLowerCase
method will return test
as a result.
In line 9, we change the value of the str
variable to the "HeLLO"
string.
In line 12, we use the toLowerCase
method to convert the str
to a string with all lowercase characters. The toLowerCase
method will return hello
as a result.