I need to be able to specify a line to insert text on in a text file. I'm using Microsoft Visual Studio 2005 and writing my program in C#.
Thanks.
Is there a way to specifiy which line to insert text in a text file using C#?
One way you can do it is to read the whole file into a string, split the string based on the carriage return into N number of strings one for each line, then use InsertAt function on the ArrayList to insert your line.
To write the output, you'll need to use a StreamWriter with WriteLine for each item in the ArrayList.
The following link explains in details how to do this, along with the C# code to do it:
http://www.mycsharpcorner.com/Post.aspx?...
Hope this help you out.
For more C# tips go to http://www.mycsharpcorner.com
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment