Dart – Check if String ends with specific other String
To check if a string ends with specific other string in Dart, call endsWith() method on this string and pass the other string as argument.
endsWith() method returns returns a boolean value of true if this string ends with the other string, or false if the this string does not end with other string.
Syntax
The syntax to call endsWith() method on this string object str and pass the other string other as argument is
</>
Copy
str.endsWith(other)
Example
In this example, we take two strings and check if the first string ends with the other string.
main.dart
</>
Copy
void main() {
var str = 'Hello World';
var other = 'rld';
if (str.endsWith(other)) {
print('This string ends with other string.');
} else {
print('This string does not end with other string.');
}
}
Output
This string ends with other string.
Conclusion
In this Dart Tutorial, we learned how to check if a string ends with specific other string, using endsWith() method of String class, with examples.
