我编写了以下方法来删除字符串中括号中的命名空间。
我想让它尽可能快。
有没有办法加速下面的代码?
using System;
namespace TestRemoveFast
{
class Program
{
static void Main(string[] args)
{
string[] tests = {
"{http://company.com/Services/Types}ModifiedAt",
"{http://company.com/Services/Types}CreatedAt"
};
foreach (var test in tests)
{
Console.WriteLine(Clean(test));
}
Console.ReadLine();
}
static string Clean(string line)
{
int pos = line.IndexOf('}');
if (pos > 0)
return line.Substring(pos + 1, line.Length - pos - 1);
else
return line;
}
}
}
最佳答案
您可以尝试并行处理,因为看起来您不需要同步处理。使用 PLINQ 的并行 foreach 就可以解决问题。
但是如果你等不及VS2010正式出来,你可以试试Poor Man's Parallel.ForEach Iterator by Emre Aydinceren
关于c# - 我怎样才能加快这个从字符串中删除文本的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2071970/