我需要用html标签替换使用某些特殊字符的括号。
示例:
“''test”“变为” test “
“ // Example //”变为“ Example ”
如何在Flutter中使用Dart语言实现这一目标?
答案 0 :(得分:1)
使用replaceFirst
可能会让您想要。
main() {
String test = "\"test\" //Example//";
final Map<String, List<String>> map = {
"\"": ["< b >", "< \/b >"],
"//": ["< i >", "< /i >"]
};
map.forEach((key, mapping) {
test = test.replaceFirst(key, mapping[0]);
test = test.replaceFirst(key, mapping[1]);
});
print(test);
}