到目前为止,我还没有找到最容易检查字符串是否以D中的某个字符开头的方法。
我想要这样的东西:
if (my_str.startswith("/")) {
// Do something
}我找到的最接近的是"chompPrefix“(here),但这并不是我真正想要的。
发布于 2013-01-02 03:25:16
在std.algorithm中有一个startsWith就是这样工作的。
import std.algorithm;
import std.stdio;
void main() {
string my_str = "/test";
if(my_str.startsWith("/"))
writeln("cool");
}发布于 2016-05-29 02:18:36
我猜这也在起作用:
string temp = "sometemp";
assert(temp[0..2] == "so")https://stackoverflow.com/questions/14113470
复制相似问题