I am using Dynamic LINQ for one of my projects to filter arrays. Library can be downloaded from NuGet Gallery link or Codeplex link. I am using version 1.0.6 from NuGet link. It is the same as LINQ but the condition can be specified using strings. Eg : myArray.Where(myDynamicQueryString)
I build QueryStrings on the fly based on left, right expressions and operators. For example, if my query is
Now, what should query string be for a query like *abc*def*?
I know it means, it could start with anything, end with anything and have anything in between abc and def, but abc and def should appear in that particular order. But, how do I translate that into a query representation using StartsWith/EndsWith/Contains(These are the ones I know, Please let me know if there are any others I can use)
It looks like what you need is IndexOf. This returns the starting index of the substring, if it exists, otherwise -1.
var.Contains("abc") && var.Contains("def") && var.IndexOf("abc") > var.IndexOf("def")
For example, if we use the string
var.IndexOf("abc") will yield
var.IndexOf("def") will yield