怎样利用c#在windows窗体对txt文件每行最前插入V和在最后插入‘1 0 0’?

例如:
aaaa bbbb cccc
dddd eeeee ffff变成如下:
v aaaa bbbb cccc 1 0 0
v dddd eeee ffff 1 0 0

 File.WriteAllLines("c:\\1.txt", File.ReadAllLines("c:\\1.txt").Select(x => "v " + x + " 1 0 0"));

一个读取文件,每次读取一行,输出流对每一行数据插入V和插入‘1 0 0’

os.writeline("{v {0} 1 0 0",is.readline());

#region 读取文件
public static ArrayList GetFile(string varFileName,string path)
{
ArrayList arrl= new ArrayList();
if (!File.Exists(varFileName))
{
return arrl;
}
StreamReader rs = new StreamReader(varFileName, System.Text.Encoding.Default);//注意编码
FileStream fs = new FileStream(path, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);

string varLine = "";
while (rs.Peek() > -1)
{
varLine = rs.ReadLine();
if (varLine == "")
{
continue;
}

else
{
sw.writeline("{v {0} 100",varLine);
}
}
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
rs.Close();
return arrl;
}
#endregion
可以试试这个,调试下。

每次读取一行,对每一行数据插入V和插入‘1 0 0’,然后输出。

亲测通过,望采纳。

 using (StreamReader sr = new StreamReader("a.txt", Encoding.UTF8))
            {
                StringBuilder sb = new StringBuilder();
                string line = null;
                while ((line = sr.ReadLine()) != null)
                {
                    line = line.Insert(line.Length, " 1 0 0").Insert(0, "v ");
                    sb.Append(line + "\r\n");
                }

                File.WriteAllText("result.txt", sb.ToString(), Encoding.UTF8);
            }

一行代码就够了
File.WriteAllLines("c:\1.txt", File.ReadAllLines("c:\1.txt").Select(x => "v " + x + " 1 0 0"));

记得加上
using System.Linq;
using System.IO;