gpt4 book ai didi

flutter - 如何在 DART 中获取两个字符串之间的子字符串?

转载 作者:IT王子 更新时间:2023-10-29 07:08:09 25 4
gpt4 key购买 nike

我怎样才能实现类似的解决方案:How to get a substring between two strings in PHP?但在 DART 中

例如我有一个字符串:
String data = "敏捷的棕色狐狸跳过懒惰的狗"
我还有另外两个字符串:quickover
我想要这两个字符串中的 data 并期待结果:
棕狐跳跃

最佳答案

您可以将 String.indexOfString.substring 结合使用:

void main() {
const str = "the quick brown fox jumps over the lazy dog";
const start = "quick";
const end = "over";

final startIndex = str.indexOf(start);
final endIndex = str.indexOf(end, startIndex + start.length);

print(str.substring(startIndex + start.length, endIndex)); // brown fox jumps
}

另请注意,startIndex包含,而endIndex不包含

关于flutter - 如何在 DART 中获取两个字符串之间的子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57186404/

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