gpt4 book ai didi

string - Dart中的strstr函数等效

转载 作者:行者123 更新时间:2023-12-03 02:52:40 25 4
gpt4 key购买 nike

Dart中是否有等效的strstr()函数?
我在PHP中使用了strstr(),我想在Dart中使用它。

谢谢。

最佳答案

这是PHP's strstr 的Dart等效项:

String strstr(String myString, String pattern, {bool before = false}) {
var index = myString.indexOf(pattern);
if (index < 0) return null;
if (before) return myString.substring(0, index);
return myString.substring(index + pattern.length);
}

输出:

strstr('name@example.com', '@');               // example.com
strstr('name@example.com', '@', before: true); // name

strstr('path/to/smthng', '/'); // to/smthng
strstr('path/to/smthng', '/', before: true); // path

关于string - Dart中的strstr函数等效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59876140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com