with this set of data in field "fOrigData":
Code: Select all
ITEM1,10,3,50,ATK,DFS,SPE,[GOF,30,33,0];
ITEM2,1,0,,ATK,DFS,SPE,[GDF,30,60,1];
ITEM22,4,3,5,ATK,DFS,SPE,[GJF,
30,1200,300];
ITEM23,1,0,,ATK,DFS,SPE,[GHF,
100,0,10];
ITEM11;10;3;50;ATK;DFS;SPE;[GOF,30,33,0];
using this code in a button
Code: Select all
on mouseUp
put field "fOrigData" into tData
replace cr with "" in tData -- get rid of returns otherwise they show up in the data
put numToChar(202) into tPlaceHolder -- just temporary delimiter
replace "];" with tPlaceHolder in tData
set the lineDelimiter to tPlaceHolder -- define line delimiter
repeat for each line aLine in tData -- the variable aLine holds one line of tData, i.e. the content of ;y,,mdfa as; not including the delimiter
if ";" is in aLine then replace ";" with comma in aLine
put aLIne & "]" & cr after tCollect -- assemble the new cleaned up version of your data, no returns and no ";" in it
end repeat
delete last char of tCollect -- a return
put tCollect into field "fCleanedData" -- now work on your data
set the lineDelimiter to cr
-- do the array
put "" into tArray
replace "[" with "" in tCollect -- in case you dont want these
replace "]" with "" in tCollect -- in case you dont want these
repeat for each line aLine in tCollect
put item 1 of aLIne into tKey
repeat with i = 2 to the number of items in aLine
put item i of aLine into tArray[tKey][i]
end repeat
end repeat
-- end array building
-- now get item 1,5,9 for every key
put "" into tCollect -- clear variable
put the keys of tArray into theKeys
-- possibly sort the the keys here
repeat for each line aLine in theKeys
put aLine & tArray[aLIne][5] & tArray[aLine][9] & cr after tCollect
end repeat
delete last char of tCollect -- a return
put tCollect into field "fRes"
end mouseUp
I get in field "fCleanedData"
Code: Select all
ITEM1,10,3,50,ATK,DFS,SPE,[GOF,30,33,0]
ITEM2,1,0,,ATK,DFS,SPE,[GDF,30,60,1]
ITEM22,4,3,5,ATK,DFS,SPE,[GJF,30,1200,300]
ITEM23,1,0,,ATK,DFS,SPE,[GHF,100,0,10]
ITEM11,10,3,50,ATK,DFS,SPE,[GOF,30,33,0]
and this in field "fRes" for item 1,5,9 of each line:
Code: Select all
ITEM1ATK30
ITEM11ATK30
ITEM2ATK30
ITEM22ATK30
ITEM23ATK100
Kind regards
Bernd
edited original data since there were 2 lines that started with "item1" and thus lead to only 4 resulting lines after array treatment since the keys were not unique.