c# - Formating txt file and displaying it to gridview -
this first post, , new c# please gentle :p. writing application reading txt files , displaying them in gridview (i later doing more things it, not important right now). of files have established system of characters (there 3 columns separated coma) , here have no problem reading them putting in list , bind gridview. have files don't have same system of characters, , have problem dealing them. can me somehow format them original system of characters (i mean 1 commas). bellow function loading list , gridview. posted example of file system of characters, , 1 not formated.
29-01-2013 03:49:31.629,some text ghs(23).asv1, more text
17-07-2011 12:12:32.643,some text dsad(1), more text
31-01-2013 08:14:08.473,some text sdfsdfsd[2], more text
not formated text has spaces @ beggining, number, (dot), , space. after start reading , rid of before. between proper data not have commas spaces. sth this.
please guys can me??
23-05-2009 12:12:45.675 text fsdf1 more text
13-02-2003 11:12:45.454 text sdfsdfs(1) more text
private void button7_click(object sender, eventargs e) { list<mycolumns> list = new list<mycolumns>(); openfiledialog openfile1 = new openfiledialog(); openfile1.multiselect = true; if (openfile1.showdialog() != dialogresult.cancel) { foreach (string filename in openfile1.filenames) { using (streamreader sr = new streamreader(filename)) { string line; while ((line = sr.readline()) != null) { string[] _columns = line.split(",".tochararray()); mycolumns mc = new mycolumns(); mc.time = _columns[0]; mc.system_description = _columns[1]; mc.user_description = _columns[2]; list.add(mc); } } } datatable listasdatatable = builddatatable<mycolumns>(list); dataview listasdataview = listasdatatable.defaultview; this.datagridview1.datasource = view = listasdataview; this.datagridview1.allowusertoaddrows = false; datagridview1.clearselection(); } textbox1.text = this.datagridview1.rows.count.tostring(); }
i thinking using reg expresions, format of text this. field1>(6)field2>(23)field3>(2)field4>(50+) field 3 spaces work delimiters, possible change them commas, while working text??
if fixed-width columns, 1 way using string.substring , trimming results each column string.trim.
Comments
Post a Comment