String array splitting in C# -


i have 2 string/text files : "1.dll" , "1a.dll" - 1.dll contains "order id" , "cartid"(separated enter '/n') - 1a.dll database witdh "id" , "name" (separated enter '/n')

i splitting strings string array. i'm separating each array string in 2 strings. 1 number position , other odd number position. after splitting both files, have 4 array strings i'm displaying 4 listboxes. - 2 arrays 1.dll displying should - 2 arrays 1a.dll missing values. here screenshot problem

//load , split "1.dll" > create 2 array strings. orderid=odd # position , cartid=even # position         string = file.readalltext(@"order/1.dll");         string[] aa = a.split('\n');         aa = aa.select(s => (s ?? "").trim()).toarray();         string[] orderid = new string[aa.length];         string[] cartid = new string[aa.length];          int dial1 = 0;         int dial2 = 0;         (int = 0; < aa.length; i++)         {             if (i % 2 == 0)             {                 orderid[dial1] = aa[i];                 dial1++;             }             else             {                 cartid[dial2] = aa[i];                 dial2++;             }         }         (int j = 0; j < aa.length / 2; j++)         {             addtocartlist.items.add(cartid[j]);             orderidlist.items.add(orderid[j]);         } //load , split "1a.dll" > create 2 array strings. id=odd # position , game=even # position          string b = file.readalltext(@"order/1a.dll");         string[] bb = b.split('\n');         bb = bb.select(s => (s ?? "").trim()).toarray();         string[] id = new string[bb.length / 2];         id = id.select(s => (s ?? "").trim()).toarray();         string[] name = new string[bb.length / 2];         name = name.select(s => (s ?? "").trim()).toarray();         string combindedstring = string.join("\n", bb.toarray());         messagebox.show(combindedstring);          int dial3 = 0;         int dial4 = 0;         (int = 0; < bb.length / 2; i++)         {             if (i % 2 == 0)             {                 id[dial3] = bb[i];                 dial3++;             }             else             {                 name[dial4] = bb[i];                 dial4++;             }         }         (int j = 0; j < bb.length / 2; j++)         {             idlist.items.add(id[j]);             namelist.items.add(name[j]);         }             (int = 0; < id.length; i++)         {             if (orderid[0] == id[i])             {                 textbox1.text = name[0];             }             if (orderid[2] == id[i])             {                 textbox2.text = name[1];             }             if (orderid[2] == id[i])             {                 textbox3.text = name[1];             }         } 

in second loop run loop half of content of bb array

for (int = 0; < bb.length / 2; i++) 

this should

for (int = 0; < bb.length; i++) 

but apart code changed lot using generic list<t> instead of creating many temporary arrays,

for example first loop written

// readalllines returns text file splitted @ newlines string[] aa = file.readalllines(@"order/1.dll");  // lists don't need create fixed size array in advance... list<string> orders = new list<string>(); list<string> carts = new list<string>();  // array iterated 2 items @ times  // of course here check number of items should // added here.... (int = 0; < aa.length; += 2) {      orders.add(aa[i]);      carts.add(aa[i+1]); } // collections have possibility add range of items // without writing loop  addtocartlist.items.addrange(carts.toarray()); orderidlist.items.addrange(orders.toarray()); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -