This commit is contained in:
parent
f90af7320f
commit
29bc7e16cc
@ -1,3 +1,3 @@
|
|||||||
// See https://aka.ms/new-console-template for more information
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
Stream.Stream.MyReplace("test.txt", 'u', 'a');
|
Stream.Stream.MyReplace("testsqdmfljqsfmlj.txt", 'u', 'a');
|
@ -41,4 +41,36 @@ public class Stream
|
|||||||
throw new ArgumentException("Error");
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -19,4 +19,13 @@ public class StreamTest
|
|||||||
global::Stream.Stream.MyReplace(filePath, toReplace, replace);
|
global::Stream.Stream.MyReplace(filePath, toReplace, replace);
|
||||||
Assert.Equal("Cfstvraimfntmagnifiquf\n", File.ReadAllText(filePath));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user