I've a question here related to string manipulation based on a specific pattern. I am trying to replace a specific pattern with a pre-defined pattern using C#
For eg:
Scenario # 1
Input: substringof('xxxx', [Property2])
Output: [Property2].Contains('xxxx')
where this string could be used within linq's Where clause.
My sol:
var key= myString.Substring(myString.Split(',')[0].Length + 1, myString.Length - myString.Split(',')[0].Length - 2);
var value = myString.Replace("," + key, "").Replace([Key from Dictionary], [Value from Dictionary]);
Expected string: key + '.' + value.Replace("('", "(\"").Replace("')", "\")");
But this works only for the above scenario. I would like to generalize it for all teh below scenario's.
Scenario's:
Input: [Property1] == 1234 and substringof('xxxx', [Property2]) and substringof('xxxx', [Property3])
Output: [Property1] == 1234 and [Property2].Contains('xxxx') and [Property3].Contains('xxxx')
Input: substringof('xxxx', [Property2]) and [Property1] == 1234 and substringof('xxxx', [Property3])
Output: [Property2].Contains('xxxx') and [Property1] == 1234 and [Property3].Contains('xxxx')
Any help would be appreciated. Thanks so much in advance!!
Final Solution:
var replaceRegex = new Regex("substringof\\(\\s*'(?<text>[^']*)'\\s*,\\s*(?<pname>[\\w\\[\\]]+)\\s*\\)");
input = replaceRegex.Replace(input, "${pname}.Contains(\"${text}\")");