2
Answers

Deleting/Editing a line in a file.

Hi all, I'm new to .NET C# and I have a challenge to delete or edit a line from a text file which contains 1000 lines. How do I check for the position of the line? And is the a replace method I could use do replace this line with a new one? Currently I search for a line I want to manipulate using Regular Expressions. All I need to know is how can I replace that line?

Answers (2)

0
Photo of Johnny GC
NA 42 0 16y
hi,
you can read the file to a big string and split it into string array (splitted by CRLF or what the terminator is) and then manipulate that array or make a List<string> out of it ;)

0
Photo of Scott Lysle
NA 28.5k 14.4m 16y
You should look at the string replace method and string remove method (also index and index of any to find the correct starting position).  You might also want to look into StringComparison (Ordinal or OrdinalIgnoreCase).

Remove takes as arguments the starting position and the length (of characters to remove).
Replace takes as arguments the old and new strings or character to replace.