I have a CLR function to replace string values. but it runs a long time. How can I improve this function and make it runs faster?
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());
}
EDIT: I changed my function to use value.Replace, it's better, but still it runs more time than expected:
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());
}
thanks!!!
Try to use StringBuilder.Replace instead.
Should notably improve performance.
This is valid like a
string.Replace(..)
substitude and not forregex
calls. But apparently the bottleneck is instring
calls.EDIT:
Example (pesudocode):