Delete or replace specific line from a file.

I’m trying to delete a specific line from a .txt file and replace it with another line. So this line will have an ID and I can search for it but I’m not sure how to delete, or better yet, replace that line with a new line.

I’ve looked at File.AppendText() and other methods but they aren’t helping. I’m using Javascript. Can anyone help please?

using system io

  function lineChanger( newText: String,  fileName :String,  line_to_edit: int)
  {
var arrLine : String[] = File.ReadAllLines(fileName);
arrLine[line_to_edit - 1] = newText;
File.WriteAllLines(fileName, arrLine);
  }