The Dart String Endswith method
The dart endsWith()
is used to check if a string ends with a given(another) String value.
Examples
void main() {
String givenString = "This MAy LoOk aWkwaRd";
print(givenString.endsWith("d"));
}
The above function will print true. Because the givenString ends with the letter d.
void main() {
String givenString = "This MAy LoOk aWkwaRd";
print(givenString.endsWith("w"));
}
The above function will print false. Because the givenString doesn’t end with w.
void main() {
String givenString = "This MAy LoOk aWkwaRd";
print(givenString.endsWith("D"));
}
Even though the string ends with the letter d, the above function will print false.
It is because The endsWith()
method is Case sensitive.
So d != D.
We can also use the endsWith()
method with multiple letters.
void main() {
String givenString = "This MAy LoOk aWkwaRd";
print(givenString.endsWith("Rd"));
}
The above function will print true because the givenString ends with Rd.
Subscribe to my Newsletter to get notified about my new posts!