【发布时间】:2020-02-09 23:59:03
【问题描述】:
快速替换文本文件中的文本。 来自:somename@somedomain.com:hello_world 至此:somename:hello_world
它需要是 FAST 并且支持多行文本文件。
我尝试将字符串分成三个部分,但它似乎很慢。下面代码中的示例。
<pre><code>
public static void Conversion()
{
List<string> list = File.ReadAllLines("ETU/Tut.txt").ToList();
Console.WriteLine("Please wait, converting in progress !");
foreach (string combination in list)
{
if (combination.Contains("@"))
{
write: try
{
using (StreamWriter sw = new
StreamWriter("ETU/UPCombination.txt", true))
{
sw.WriteLine(combination.Split('@', ':')[0] + ":"
+ combination.Split('@', ':')[2]);
}
}
catch
{
goto write;
}
}
else
{
Console.WriteLine("At least one line doesn't contain @");
}
}
}</code></pre>
这是一种将文本文件中的每一行从 somename@somedomain.com:hello_world
收件人:somename:hello_world 然后将其保存为不同的文本文件。
!记住域位总是变化的!
【问题讨论】:
-
请准确解释您要对输入文本执行的操作。
标签: c# regex list visual-studio replace