feat: Finish MyReplace
Some checks failed
Tests / Unit Testing1 (push) Failing after 42s

This commit is contained in:
2023-11-02 20:51:39 +01:00
parent 1dc4d308e4
commit 429e717a6e
5 changed files with 46 additions and 1 deletions

BIN
Stream/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -1,3 +1,3 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
Stream.Stream.MyReplace("test.txt", 'u', 'a');

View File

@ -7,4 +7,38 @@ public class Stream
{
return File.Exists(path);
}
public static void MyReplace(string path, char toReplace, char replace)
{
string preResult = String.Empty;
string result = String.Empty;
try
{
using (StreamReader sr = new StreamReader(path))
{
preResult = sr.ReadToEnd();
}
foreach (var chara in preResult)
{
if (chara == toReplace)
{
result += replace;
}
else
{
result += chara;
}
}
using (StreamWriter sw = new StreamWriter(path))
{
sw.WriteLine(result);
}
}
catch (Exception)
{
throw new ArgumentException("Error");
}
}
}