怎样用程序修改记事本中的指定行的字符串?

怎样用程序修改记事本中的指定行的字符串?
比如原第二行:abcdefg
换为这样的一行:uvwxyz
具体怎样写代码?谢谢
[79 byte] By [hantse-hantse] at [2007-12-16]
# 1
you need to read all lines out, replace the second line, then write them back
saucer-思归 at 2007-10-22 > top of Msdn China Tech,.NET技术,C#...
# 2
for example

using System;
using System.IO;
using System.Text;

string fileName = "test.txt";
String sReplacement = "hello world";
int n = -1; // line number to replace

StringBuilder sb = new StringBuilder();
StreamReader sr = new StreamReader(fileName,Encoding.ASCII);

int nLine=0;
while (sr.Peek() > -1)
{
nLine++;
String s = sr.ReadLine();
if (nLine == n)
sb.Append(sReplacement+"\r\n");
else
sb.Append(s+"\r\n");
}

sr.Close();

StreamWriter sw = new StreamWriter(fileName,false, Encoding.ASCII);
sw.Write(sb.ToString());
sw.Close();
saucer-思归 at 2007-10-22 > top of Msdn China Tech,.NET技术,C#...