2

I need a function to test if a string ends with some suffix. I can use 'lastIndexOf' for this task, but I wonder if there is a standard phobos' function?

Denis Gladkiy
  • 2,084
  • 1
  • 26
  • 40

1 Answers1

7

Yes, it does. std.algorithm.endsWith works with strings as well as other arrays and ranges. Example:

void main()
{
    import std.algorithm.searching, std.stdio;
    auto s = "Sunday";
    auto b = s.endsWith("ay");
    writeln(b); // true
}
Vladimir Panteleev
  • 24,651
  • 6
  • 70
  • 114