我写了下面这个方法来删除字符串中括号内的命名空间。
我希望尽可能地让它运行得更快。 有什么方法可以加速以下代码吗?
我希望尽可能地让它运行得更快。 有什么方法可以加速以下代码吗?
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;
}
}
}