Dart String toLowerCase()
Syntax & Examples
Syntax of String.toLowerCase()
The syntax of String.toLowerCase() method is:
String toLowerCase()
This toLowerCase() method of String converts all characters in this string to lower case.
Return Type
String.toLowerCase() returns value of type String
.
✐ Examples
1 Convert a string to lowercase
In this example,
- We create a string
str
with the value 'Hello, World!'. - We then use the
toLowerCase()
method to convert all characters in the string to lowercase. - The lowercase version of the string is stored in
lowerCaseStr
. - We print both the original and lowercase strings to standard output.
Dart Program
void main() {
String str = 'Hello, World!';
String lowerCaseStr = str.toLowerCase();
print('Original String: $str');
print('Lowercase String: $lowerCaseStr');
}
Output
Original String: Hello, World! Lowercase String: hello, world!
2 Convert another string to lowercase
In this example,
- We create a string
str
with the value 'ABCDEF'. - We then use the
toLowerCase()
method to convert all characters in the string to lowercase. - The lowercase version of the string is stored in
lowerCaseStr
. - We print both the original and lowercase strings to standard output.
Dart Program
void main() {
String str = 'ABCDEF';
String lowerCaseStr = str.toLowerCase();
print('Original String: $str');
print('Lowercase String: $lowerCaseStr');
}
Output
Original String: ABCDEF Lowercase String: abcdef
3 Convert a sentence to lowercase
In this example,
- We create a string
str
with the value 'Lorem Ipsum Dolor Sit Amet'. - We then use the
toLowerCase()
method to convert all characters in the string to lowercase. - The lowercase version of the string is stored in
lowerCaseStr
. - We print both the original and lowercase strings to standard output.
Dart Program
void main() {
String str = 'Lorem Ipsum Dolor Sit Amet';
String lowerCaseStr = str.toLowerCase();
print('Original String: $str');
print('Lowercase String: $lowerCaseStr');
}
Output
Original String: Lorem Ipsum Dolor Sit Amet Lowercase String: lorem ipsum dolor sit amet
Summary
In this Dart tutorial, we learned about toLowerCase() method of String: the syntax and few working examples with output and detailed explanation for each example.