The syntax of String.trimRight() method is:
String trimRight()
This trimRight() method of String returns the string without any trailing whitespace.
String.trimRight() returns value of type String
.
In this example,
str1
with trailing whitespace.trimRight()
method on str1
to remove the trailing whitespace.void main() {
String str1 = ' Dart ';
String trimmed1 = str1.trimRight();
print('Trimmed right string 1: $trimmed1');
}
Trimmed right string 1: Dart
In this example,
str2
with trailing whitespace.trimRight()
method on str2
to remove the trailing whitespace.void main() {
String str2 = ' Dart ';
String trimmed2 = str2.trimRight();
print('Trimmed right string 2: $trimmed2');
}
Trimmed right string 2: Dart
In this example,
str3
without trailing whitespace.trimRight()
method on str3
, it does not modify the string.void main() {
String str3 = ' Dart';
String trimmed3 = str3.trimRight();
print('Trimmed right string 3: $trimmed3');
}
Trimmed right string 3: Dart
In this Dart tutorial, we learned about trimRight() method of String: the syntax and few working examples with output and detailed explanation for each example.