ここで、特定のパターンに基づく文字列操作に関連する質問があります。C# を使用して、特定のパターンを定義済みのパターンに置き換えようとしています。
例:
シナリオ 1
Input: substringof('xxxx', [Property2])
Output: [Property2].Contains('xxxx')
Where
この文字列は、linq の句内で使用できます。
私のソル:
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("')", "\")");
ただし、これは上記のシナリオでのみ機能します。以下のすべてのシナリオに一般化したいと思います。
シナリオ:
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')
どんな助けでも大歓迎です。よろしくお願いします!
最終的解決:
var replaceRegex = new Regex("substringof\\(\\s*'(?<text>[^']*)'\\s*,\\s*(?<pname>[\\w\\[\\]]+)\\s*\\)");
input = replaceRegex.Replace(input, "${pname}.Contains(\"${text}\")");