Sunday 15 July 2012

c# - Output name varies on different line -



c# - Output name varies on different line -

i writing downwards programme write names in text file accoring 2 nd cloumn names, can see here https://imageshack.com/i/eyw14lh6j. output view shown in link. have done is, reading line line text of 2 nd column , generating names according max_pn column name.

for ex: in above output view need when ever same string (100-0145 comes need carousel:4 shown) wanted if 2nd column names alike need same name appeared in location column. happening code is, if same name appears after 1 or 2 3 lines not reading. how can rectify this. please help me out.

my code snippet:

int[] cols = new int[] { 15, 15, 25, 15, 15 }; string[] strlines = system.io.file.readalllines(textbox1.text); stringbuilder sb = new stringbuilder(); string line = string.empty; string lastcomment = string.empty; string carouselname = "carousel"; int icarousel = 0; (int = 0; < strlines.length; i++) { line = removewhitespace(strlines[i]).trim(); string[] cells = line.replace("\"", "").split('\t'); (int c = 0; c < cells.length; c++) sb.append(cells[c].replace(" ", "_").padright(cols[c])); if (cells.length > 1) { if (cells[1] != lastcomment & > 0) { icarousel++; if (icarousel > 45) icarousel = 1; lastcomment = cells[1]; } if (i == 0) sb.append("location".padright(15)); else sb.append(string.format("{0}:{1}", carouselname, icarousel).padright(15)); } sb.append("\r\n"); } system.io.file.writealltext(textbox1.text, sb.tostring());

try saving names in dictionary int number of carousel. can check carousel matches name. @ sample:

dictionary<string,int> namesforcarousels = new dictionary<string,int>();

...

if (cells.length > 1) { var name = cells[1]; int carouselnumber; if (namesforcarousels.trygetvalue(name, out carouselnumber) == false) { carouselnumber = icarousel++; namesforcarousels[name] = carouselnumber; } if (i == 0) sb.append("location".padright(15)); else sb.append(string.format("{0}:{1}", carouselname, carouselnumber).padright(15)); }

c# wpf visual-studio-2010 visual-studio replace

No comments:

Post a Comment