I want to find each line in a text file that contains the sequence “letter or number”, “new line”, “letter or number”, and then replace “new line” with “space”.
This is what I have tried so far:
private void button3_Click(object sender, EventArgs e)
{
string pathFOSE = @"D:\Public\temp\FOSEtest.txt";
string output = Regex.Replace(pathFOSE, @"(?<=\w)\n(?=\w)", " ");
string pathNewFOSE = @"D:\Public\temp\NewFOSE.txt";
if (!System.IO.File.Exists(pathNewFOSE))
{
using (System.IO.StreamWriter sw = System.IO.File.CreateText(pathNewFOSE))
{
}
File.AppendAllText(pathNewFOSE, output);
}
}
But my whole program creates a new text file containing only this line "D:\Public\temp\FOSEtest.txt"
Any idea what is going on? Also is there a \nproper way to search for newlines in a text file in Windows7? Thanks
Change . I made the changes suggested by Avinash and added that I am working on Windows 7.
2. , , Replace , , , .
Final Edit: stribizhev, . , !