I have a requirement where I need to read a query from access db and modify the query to replace all the keywords in the query to SQL executable query.. For eg: say there is a query 'Select key from table1"
here "key" is a reserved keyword.which has to be modified as "Select [key] from table1" (which will work in sql).
there is a possibility that the query can have multiple keywords..so I have a regex as below.
string pattern = "Key|IN|ON|VIEW]";
Regex rgx = new Regex(pattern);
I have the below code..which checks for the patterns..
string pattern = "Key|IN|ON|VIEW]";
Regex rgx = new Regex(pattern);
string strModifiedQuery = string.Empty;
strModifiedQuery = strQueryText;
foreach (Match m in rgx.Matches(pattern))
{
Console.WriteLine(m.Value);
if (m.Value == "Key")
{
strModifiedQuery = rgx.Replace(strModifiedQuery, "[Key]");
}
if (m.Value == "IN")
{
strModifiedQuery = rgx.Replace(strModifiedQuery, "[IN]");
}
if (m.Value == "ON")
{
strModifiedQuery = rgx.Replace(strModifiedQuery, "[IN]");
}
Is there a better way in c# to replace the matched pattern with a proper value?
Key|IN|ON|VIEW]wrong pattern...