2

我需要一个函数来测试字符串是否以某些后缀结尾。我可以使用“lastIndexOf”来完成这项任务,但我想知道是否有标准的 phobos 功能?

4

1 回答 1

7

是的,它确实。std.algorithm.endsWith适用于字符串以及其他数组和范围。例子:

void main()
{
    import std.algorithm.searching, std.stdio;
    auto s = "Sunday";
    auto b = s.endsWith("ay");
    writeln(b); // true
}
于 2014-09-11T12:43:21.080 回答