How to improve Replace function in CLR function?

I have a CLR function to replace string values. but it lasts a long time. How can I improve this feature and speed it up?

    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, this is better, but still it works longer 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());

    }

thank!!!

0
source share
1 answer

Try StringBuilder.Replace instead .

It should significantly increase productivity.

This acts as a wildcard string.Replace(..), not for calls regex. But apparently the bottleneck is in the stringchallenges.

EDIT

Example (pesudocode):

char[] c = new char[]{'.', ' '}; 
Value = Value.Trim(c);
var sb = new StringBuilder(Value);   

sb.Replace("'", "");
sb.Replace(")", " ");
sb.Replace("(", " ");
sb.Replace("-", " ");
sb.Replace("_", " ");
sb.Replace("רח", "");
+1

All Articles