我有一个 CLR 函数来替换字符串值。但它运行了很长时间。如何改进此功能并使其运行得更快?
public static SqlString ReplaceValues(String Value)
{
// Put your code here
char[] c = new char[] { '.' };
Value= Value.Trim();
Value = Value.Trim(c);
Value = Value.Replace("'", "").Replace(")", " ").Replace("(", " ").Replace("-", " ").Replace("_", " ");
Value = Regex.Replace(Value, @"[י", "+[י");
Value = Regex.Replace(Value, @"\s+", " ");
return new SqlString(Value.Trim());
}
编辑:我将函数更改为使用 value.Replace,它更好,但它的运行时间仍然比预期的要长:
public static SqlString ReplaceStreetValues(String Value)
{
// Put your code here
Value = Value.Trim();
char[] c = new char[]{'.'};
Value = Value.Trim(c);
Value= Value.Replace("'", "").Replace(")", " ").Replace("(", " ").Replace("-", " ").Replace("_", " ").Replace("רח", "");
while (Value.IndexOf(" ")!=-1)
Value = Value.Replace(" ", " ");
while (Value.IndexOf("hh") !=-1)
Value = Value.Replace("hh", "h");
return new SqlString(Value.Trim());
}
谢谢!!!