在D语言的标准库中,stripRight函数会去除字符串末尾的所有与参数匹配的字符。因此,调用four.stripRight("two")会去除字符串末尾的所有"t"和"o"字符,而不是仅去除"two"。

如果想要去除字符串末尾的"two",可以使用以下代码:

string four = q"EOF
one two
EOF";
four = stripRight(four, "two");
writeln(four);

这里使用了std.string中的stripRight函数,并将字符串和匹配的字符串作为两个参数传入。这样就可以正确地去除字符串末尾的"two",输出结果为"one "。

dlang语言2022年以后如下代码调用了stripRight字符串four还是为one two请帮我分析原因并改正或者给出去除尾部two的方法import stdstdio;import stdalgorithm;import stdstring;void main string four = qEOFone twoEOF; four = fourstripRighttwo;

原文地址: https://www.cveoy.top/t/topic/fkW2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录