检查字符串是否以D/phobos中的子字符串开头?

Sam*_*mpa 3 d phobos

到目前为止我还没有找到如何最容易检查字符串是否以D中的某个字符开头.

我想要的东西:

if (my_str.startswith("/")) {
    // Do something
}
Run Code Online (Sandbox Code Playgroud)

我发现最接近的是"chompPrefix"(这里),但这不是我想要的.

Ada*_*ppe 5

在std.algorithm中有一个startsWith可以像这样工作.

import std.algorithm;
import std.stdio;
void main() {
    string my_str = "/test";
    if(my_str.startsWith("/"))
        writeln("cool");
}
Run Code Online (Sandbox Code Playgroud)