I have a question related to string manipulation based on a specific pattern. I am trying to replace a specific template with a predefined template using C #
For instance,
Scenario number 1
Input: substringof('xxxx', [Property2]) Output: [Property2].Contains('xxxx')
where this line can be used in the linq Where expression.
My angry:
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 only works for the above scenario. I would like to generalize it to all the below scenarios.
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 greatly appreciated. Thank you very much in advance!
Final decision:
var replaceRegex = new Regex("substringof\\(\\s*'(?<text>[^']*)'\\s*,\\s*(?<pname>[\\w\\[\\]]+)\\s*\\)"); input = replaceRegex.Replace(input, "${pname}.Contains(\"${text}\")");
source share