diff --git a/Stream/Program.cs b/Stream/Program.cs index 0f5d5ee..b55391d 100644 --- a/Stream/Program.cs +++ b/Stream/Program.cs @@ -1,3 +1,3 @@ // See https://aka.ms/new-console-template for more information -Stream.Stream.MyReplace("test.txt", 'u', 'a'); \ No newline at end of file +Stream.Stream.MyReplace("testsqdmfljqsfmlj.txt", 'u', 'a'); \ No newline at end of file diff --git a/Stream/Stream.cs b/Stream/Stream.cs index 6bf7b6a..c88e095 100644 --- a/Stream/Stream.cs +++ b/Stream/Stream.cs @@ -41,4 +41,36 @@ public class Stream throw new ArgumentException("Error"); } } + + public static void DeleteLines(string path, int n) + { + string temp = String.Empty; + string final = String.Empty; + int i = 0; + try + { + using (StreamReader sr = new StreamReader(path)) + { + string? line; + while ((line = sr.ReadLine()) != null) + { + if (i % n != 0) + { + final += line + "\n"; + } + + i++; + } + using (StreamWriter sw = new StreamWriter(path)) + { + + sw.Write(final); + } + } + } + catch (Exception) + { + throw new ArgumentException("Error"); + } + } } \ No newline at end of file diff --git a/Tests/Stream/StreamTest.cs b/Tests/Stream/StreamTest.cs index 6c1aec7..4d070f7 100644 --- a/Tests/Stream/StreamTest.cs +++ b/Tests/Stream/StreamTest.cs @@ -19,4 +19,13 @@ public class StreamTest global::Stream.Stream.MyReplace(filePath, toReplace, replace); Assert.Equal("Cfstvraimfntmagnifiquf\n", File.ReadAllText(filePath)); } + + [Theory] + [InlineData("DeleteLineTestFile.txt", 2)] + + public void DeleteLineTest(string filePath, int n) + { + global::Stream.Stream.DeleteLines(filePath, n); + Assert.Equal("1\n3\n5\n7\n9\n11\n", File.ReadAllText(filePath)); + } } \ No newline at end of file