Hi, I am new to C#. Please help me to solve this problem. Given an "input.txt", I want to obtain the "output.txt" as below:
input.txt
5,5
A(,)= 4.6;
B(,)= 0.1;
C(,)= 0.2;
D(,)= 1.6;
E(,)= 245;
F(,)= 3.3;
5,15
A(,)= 6.3;
B(,)= 0.9;
C(,)= 0.2;
D(,)= 1.6;
E(,)= 242;
F(,)= 2.9;
5,25
A(,)= 7.3;
B(,)= 0.2;
C(,)= 0.3;
D(,)= 1.5;
E(,)= 238;
F(,)= 1.9
output.txt
A(5,5)= 4.6;
B(5,5)= 0.1;
C(5,5)= 0.2;
D(5,5)= 1.6;
E(5,5)= 245;
F(5,5)= 3.3;
A(5,15)= 6.3;
B(5,15)= 0.9;
C(5,15)= 0.2;
D(5,15)= 1.6;
E(5,15)= 242;
F(5,15)= 2.9;
A(5,25)= 7.3;
B(5,25)= 0.2;
C(5,25)= 0.3;
D(5,25)= 1.5;
E(5,25)= 238;
F(5,25)= 1.9
From the input.txt, I want to replace the first six "(,)" with "(5,5)", the next six "(,)" with "(5,15)", and the last six "(,)" with "(5,25)". The problem I faced is how to loop 3 times and replace the (,) with "(5,5)", "(5,15)" and "(5,25)"?
In the meantime, I want to delete "5,5", "5,15" and "5,25" lines so that the output.txt will not have these lines.
using System.Text;
using System;
using System.IO;
namespace txt_Console_CSharp
{
class Program
{
static void Main(string[] args)
{
String strFile = File.ReadAllText("c:\\input.txt");
int ind = 0;
int w, h;
while (ind < 3)
{
w = 5;
h = 5 + 10*(ind%4);
for (int i = 0; i < 6; i++) //loop "(,)" for six time
{
strFile = strFile.Replace("(,)", "("+w.ToString() + "," + h.ToString()+")");
}
ind++;
}
File.WriteAllText("d:\\output.txt", strFile);
}
}
}
Please advise.
Thank you.