Search code examples
dphobos

Does phobos (D's standard library) contain "endsWith" for string type?


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?


Solution

  • 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
    }