gpt4 book ai didi

flutter - 将字符串拆分为 Dart 中的关键字

转载 作者:行者123 更新时间:2023-12-05 08:45:28 27 4
gpt4 key购买 nike

如果我有一个字符串,上面写着“This is a good example”,有什么方法可以将它拆分为 dart 中的以下输出:

This
This is
This is a
This is a good
This is a good example

最佳答案

我会这样做:

String text = "This is a good example";
List<String> split = text.split(" ");
for (var i = 0; i < split.length; i++) {
print(split.sublist(0, i + 1).join(" "));
}

关于flutter - 将字符串拆分为 Dart 中的关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72629642/

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