有数组形如:
PList="1042-粉-XL-1,1019-粉-XL-3,1052-藏青-L-5,1042-粉-XL-6,1052-藏青-L-3,1052-粉-XL-4,"
(其代表的含义为:商品ID-颜色-尺码-数量)
现在要做的工作就是:
asp筛选出,有相同商品的数组值,并且商品数量累加上,重新生成PList,拿上面的例子来讲,1042-粉-XL、1052-藏青-L有重复的,所以最终新的Plist应该是:
PList="1042-粉-XL-7,1019-粉-XL-3,1052-藏青-L-8,1052-粉-XL-4,"
请问这个怎么实现?(PList是由表单提交过来的,内容是动态变化的)
谢谢!
正则。。。。
VBScript code:
<%
dim PList
PList="1042-粉-XL-1,1019-粉-XL-3,1052-藏青-L-5,1042-粉-XL-6,1052-藏青-L-3,1052-粉-XL-4,"
response.write filter(plist)
function filter(stng)
dim re,arr,item,matches,i,flag
redim arr(1,-1)
Set re=new RegExp
with re
.ignorecase=true
.global=true
.pattern="(.*?)-(\d+),"
If .test(stng) then
set matches = re.execute(stng)
For Each item In matches
flag=0
for i=0 to ubound(arr,2)
if arr(0,i)=item.submatches(0) then
flag=1
arr(1,i)=clng(arr(1,i))+clng(item.submatches(1))
exit for
en