This commit is contained in:
@ -1,3 +1,3 @@
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user