I want to read a batch file line by line and if the line contains "UnitTest1.trx",
I want to replace "/testcasefilter:FullyQualifiedName~AutomationTestSamples.UnitTest1" with "/test".
I tried the following code but when I opened the file nothing was replaced. Any idea please?
string[] str = File.ReadAllLines(@"C:\Test\test.bat"); for (int i = 0; i < str.Length; i++) { if (str[i].Contains(trxName)) { str[i].Replace(str[i].Substring(str[i].IndexOf("/testcasefilter")), "/test"); } }
In the code sample above you are just reading the file contents in an string array. You need to write back those lines to the file as well to get the desired results.
In the code sample above you are just reading the file contents in an string array. You need to write back those lines to the file as well to get the desired results.
Also string.Replace https://docs.microsoft.com
Regards,
Chinmay.