loops - Iterate through two Arrays VBscript -
i have 2 arrays, first 1 has similar values, , in sorted order, second array csv map. want how concatenate values in first array, grouped together, based on second value of map
what have:
arr1 map ---- --- x x, 1 x y, 1 x z, 2 y y z
what want:
newarr ---- x x x y y, 1 z , 2
my code:
for each x in arr1 each y in map line = split(y, ",") if instr(x, line(0)) redim preserve newarr(i) newarr(i) = newarr(i) & x elseif instr(x, line(1)) redim preserve newarr(i) newarr(i) = newarr(i) & x else = + 1 end if next next
my logic compare val in arr1 map(0), if there similarities, put in array, if there aren't, check map(1), if there match there, append value in newarr(i). iterate if there no matches. code not doing that. thoughts?
the op asked if array sorted alphabetically based of map.
arr1 = array("x","x","x","y","y","z") map = array("x,b","y,b","z,a")
dim indexlist, dictkeys set indexlist = createobject("system.collections.arraylist") set dictkeys = createobject("scripting.dictionary") dim arr1, map, newarr, temp, x, y arr1 = array("x","x","x","y","y","z") map = array("x,b","y,b","z,a") each y in map line = split(y, ",") if not indexlist.contains(cstr(line(1))) indexlist.add cstr(line(1)) next indexlist.sort each y in map line = split(y, ",") if not dictkeys.exists(line(0)) dictkeys.add line(0), indexlist.lastindexof(cstr(line(1))) next redim newarr(indexlist.count - 1) each y in arr1 if isempty(newarr(dictkeys(y))) redim temp(0) else temp = newarr(dictkeys(y)) redim preserve temp(ubound(temp) + 1) end if temp(ubound(temp))= y newarr(dictkeys(y)) = temp next = 0 ubound(newarr) temp = newarr(i ) redim preserve temp(ubound(temp) + 1) temp(ubound(temp))= + 1 newarr(i ) = temp next each x in newarr wscript.echo join(x , ",") next
Comments
Post a Comment