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

检查字符串是否以D/phobos中的子字符串开头?,d,phobos,D,Phobos,到目前为止,我还没有找到最容易检查字符串是否以D中的某个字符开头的方法 我想要像这样的东西: if (my_str.startswith("/")) { // Do something } 我找到的最接近的是“chompPrefix”(),但这并不是我真正想要的。std.algorithm中有一个startsWith,它会像那样工作 import std.algorithm; import std.stdio; void main() { string my_str = "/t

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

我想要像这样的东西:

if (my_str.startswith("/")) {
    // Do something
}

我找到的最接近的是“chompPrefix”(),但这并不是我真正想要的。

std.algorithm中有一个startsWith,它会像那样工作

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

我认为这也是可行的:

string temp = "sometemp";
assert(temp[0..2] == "so")

啊,很明显我错过了谷歌“startswith site:dlang.org”:)谢谢!