Truncate CSV file in C# -


i have csv file 48 rows of integers. using openfiledialog feature of visual c# allow user select file. want have program truncate file down 24 rows. there truncate function can use easily? if not how can go doing so? below have far...

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.io; using system.linq; using system.text; using system.windows.forms;  namespace sts_converter {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }          private void select_click(object sender, eventargs e)         {             int size = -1;             dialogresult result = openfiledialog1.showdialog(); // show dialog.             if (result == dialogresult.ok) // test result.             {                 string file = openfiledialog1.filename;                 try                 {                     string text = file.readalltext(file);                     size = text.length;                 }                 catch (ioexception)                 {                 }             }             console.writeline(size); // <-- shows file size in debugging mode.             console.writeline(result); // <-- debugging use only.         }      } } 

it easy as:

string file = openfiledialog1.filename; file.writealllines(     file,      file.readlines(file).take(28).toarray() ); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -