How To Update a Specific Line with StreamWriter?

How To Update a Specific Line with StreamWriter?

Hey Guys…
I’ve got a problem:

I can’t update a specific line without eraseing everything that was written before…
And nobody seems to ask this question…

Is that even possible?

I ussing c#, so please if you can write your code in c#…

Thank you very much!

use the string.Replace method if you know what you need to replace
but you’ll have to rewrite the entire text once you replaced your line.

also look: stream - Edit a specific Line of a Text File in C# - Stack Overflow

Bruce Afruz’s answer is maybe a better alternative for you

static void lineChanger(string newText, string fileName, int line_to_edit)
     string[] arrLine = File.ReadAllLines(fileName);
     arrLine[line_to_edit - 1] = newText;
     File.WriteAllLines(fileName, arrLine);