Split Array into 2D based on 2 parameters C# -
i have text file have split string array based on new line.
string[] arr = s.split('\n');
now, need further categorize 2-dimensional array wherein each column new "transaction". text file contains info bank transactions, example being given below:
21...... 22.... 23..... 31.... 32..... 31..... 32..... 21.... 21..... 22....
the beginning of numbers signify new tx record begins @ new line. want make 2d array wherein each column grouped 1 tx beginning 21 until comes across next 21 (so record before it).
(int = 0; < arr.length; i++) { if (arr[i].startswith("21")) { indices[i] = i; } } i tried write code above check array element beginning 21 , storing index ends storing indices.
any appreciated!
what you'd need
string[] arr = s.split('\n'); list<list<string>> listoflists = new list<list<string>>(); //dynamic multi-dimensional list //list hold lines after line "21" , line list<string> newlist = new list<string>(); listoflists.add(newlist); for(int = 0; < arr.length; i++) { if(arr[i].startswith("21")) { if(newlist.count > 0) { newlist = new list<string>(); //make new list column listoflists.add(newlist); //add list of lines (one column) main list } } newlist.add(arr[i]); //add line column }
Comments
Post a Comment