gpt4 book ai didi

javascript - 使用带有 flutter 的js全局文本替换代码

转载 作者:行者123 更新时间:2023-12-03 04:46:14 25 4
gpt4 key购买 nike

我之前已经映射了JavaScript全局文本替换代码行(超过100行),如下例所示,很难再次映射它们以与flutter兼容。

res = str.replace(/blue/g, "red");
res = str.replace(/black/g, "white");
res = str.replace(/green/g, "yellow");
.
.
.

我想在flutter应用程序中使用此映射替换输入文本,而我是flutter的新手.thitext替换机制可以使用任何方法或技巧吗?

最佳答案

使用replaceAll方法,它将所有与from匹配的子字符串替换为replace。

var res;
res = str.replaceAll('blue', 'red');
res = str.replaceAll('black', 'white');
res = str.replaceAll('green', 'yellow');
...

关于javascript - 使用带有 flutter 的js全局文本替换代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62241662/

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