Hi
I have text file, it looks like given below
Head
description
Head
description
Head
description
Head
description
I want to replace Head to 1.Head,2.Head,... I tried to use replace function it replace whole documents wherever Head.
Please guide me how i do this task...
Loading
jaya kumarPosted Jun 6, 2011, 4:44 AM
Jaganathan BantheswaranPosted Jun 6, 2011, 3:49 AM
Frogleg...
You the man...
I am in Words ... You are in Execution .... Good .
FroglegPosted Jun 6, 2011, 2:59 AM
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
renameHead();
}
public void renameHead()
{
int lineCount = 1;
int flen = File.ReadAllLines(@"head.txt").Length;
string[] str = new string[flen];
using (StreamReader sr = new StreamReader(@"head.txt"))
{
for (int i = 0; i < flen; i++)
{
str[i] = sr.ReadLine();
}
}
using (StreamWriter sw = new StreamWriter(@"heada.txt"))
{
for (int ii = 0; ii < flen; ii++)
{
if (str[ii] == "Head")
{
sw.WriteLine(Convert.ToString(lineCount) + ".Head");
lineCount++;
}
else
{
sw.WriteLine(str[ii]);
}
}
}
}
}
}
Jaganathan BantheswaranPosted Jun 6, 2011, 1:24 AM
You can replace as you want using your own program. [ have to create in such a manner ]
If you use Replace function in Text editor you cant replace like 1.Head .. so on..
You have to do manually.