我正在为此应用程序使用颤振,但我在应用程序的逻辑方面遇到了问题。任何帮助深表感谢。
应用程序目标:通过以下方式将所有输入的缩写解码(替换)为: - 用户通过文本框输入文本 - 应用程序查找任何缩写(几个)并仅用文本替换缩写。
我能够做到它会有一些缩写,但在我的情况下,所有缩写都应该在输入文本中,否则它不起作用或第二个索引不起作用。我尝试了几种不起作用的方法,我使用 2 个列表作为 abv 和相应的文本。
这是代码。
List<String> coded = ["GM", "HOT", "YAH"]; //ABV list
List<String> decoded = ["Gmail", "Hotmail", "Yahoo"]; //corresponding list
Map<String, String> map = new Map.fromIterables(coded, decoded);
String txt = "HOT was the best until GM took over"; //input text
void main() {
if ((txt.contains(coded[0]))) { //GM
String result = txt.replaceAll(coded[0], decoded[0]); //Replace with Gmail
print(result);
}
else if ((txt.contains(coded[0])) && (txt.contains(coded[1]))) {
String result = (txt.replaceAll(coded[0], decoded[0]));
(txt.replaceAll(coded[1], decoded[1]));
print(result);
} …Run Code Online (Sandbox Code Playgroud)