I have a function that should replace any string found in another string with the criteria that the string to replace starts with a @
and it must be replaced only when it is an entire word.
But the code below does not work. The problem is with the character, @
, because if I use another character at the start, for example, a X, it works. However even putting the @
symbol between square brackets did not help.
public static string DB_Replace_Str(string st, string stFrom, string stTo)
{
stFrom = stFrom.Replace("@", "[@]");//this does not help
string pattern = @"\b" + stFrom + @"\b";
return Regex.Replace(st, pattern, stTo);
}
I post some example strings here:
st
="SELECT @table_Software.*, @table_Teile.@Id as @TeilId FROM @table_Software LEFT JOIN @table_Teile ON @table_Software.@Id = @table_Teile.@Software_Id WHERE @table_Software.@Id = 11"
stFrom
="@table_Software"
stTo
="tblSoftware"