所以我试图拆分包含运算符的字符串。
这是例子:
var string= "12+13+45-78*45/91=100"
(how can i achieve this using dart)
var result = [12,+,13,+,45,-,78,*,45,/,91,=,100]
有没有人有办法解决吗?
最佳答案
您可以使用以下方法进行操作:
RegExp exp = new RegExp(r"\d+|\+|-|\*|/|=");
String str = "12+13+45-78*45/91=100";
Iterable<Match> matches = exp.allMatches(str);
var list = matches.map((m) => (m.group(0)));
print(list);
它将打印:(12, +, 13, +, 45, -, 78, *, 45, /, 91, =, 100)
关于string - 使用 flutter 分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63198471/