例如:01 1000123456 10 230425000123 11 230425 17 240425(批号可能存在字母,中间没有空格,编码等的字数不固定)
规则:(01)商品编码(10)生产批号(11)生产日期(17)有效期至
测试数据:
[
{"splitChar":"01","key":"code","name":"商品编码"},
{"splitChar":"10","key":"batchNumber","name":"生产批号"},
{"splitChar":"11","key":"produceDate","name":"生产日期"},
{"splitChar":"17","key":"expireDate","name":"有效期至"},
{"splitChar":"","key":"none","name":"无"},
{"splitChar":"","key":"none"},
{"splitChar":"","key":"none"},
{"splitChar":"","key":"none"}
...
]
想要的结果是:
{
key: "code",
val: 1000123456
}, {
key: "batchNumber",
val: 230425000123
}
我写了一堆,有比较简洁的方法吗,请指教