[英]How to extract strings from a list of string with a condition in flutter?
I have a list of strings based on google ML kit blocks and i want to get a specific strings in a range between CHECK # 259395 and SUB-TOTAL..我有一个基于 google ML kit 块的字符串列表,我想获得介于 CHECK # 259395 和 SUB-TOTAL 之间的特定字符串。
List<String> item = [
'Line',
'Restaurant & Cafe',
'Abdomen',
'079900000000',
'VAT# 16669304',
'TABLE',
'19-06 2022 12:37',
'CHECK # 289395 TABLE#',
'2 MINERAL WATER',
'1 HOT CHOCOLATE',
'1 TURKISH COFFEE DOUBLE',
'SUB-TOTAL',
];
I just want to display any item between 'CHECK # 259395' and 'SUB-TOTAL' after i extracted these strings from ML kit blocks, the main idea that i want to get only items without any additional information from the invoice.从 ML 套件块中提取这些字符串后,我只想显示“CHECK # 259395”和“SUB-TOTAL”之间的任何项目,主要思想是我只想从发票中获取没有任何其他信息的项目。
The items are 2 MINERAL WATER, 1 HOT CHOCOLATE and 1 TURKISH COFFEE DOUBLE.这些项目是 2 矿泉水、1 热巧克力和 1 土耳其咖啡双。
Knowing that this data is not static, so it can be changed if i scanned another invoice.知道此数据不是静态的,因此如果我扫描另一张发票,它可以更改。
How can i achieve this ?我怎样才能做到这一点?
你可以这样做:
var result = item.sublist(item.indexOf('CHECK # 259395') + 1, item.indexOf('SUB-TOOTAL'));
print(item[index]);
在您想要的索引位置,如 item[2] 将打印此“1 HOT CHOCOLATE”,
you can easily get like this你可以很容易地得到这样的
item[0]= 'CHECK # 259395', item[0]='检查#259395',
item[item.length]= 'SUB-TOOTAL', item[item.length]= 'SUB-TOOTAL',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.