The Where operator is used for filtering. For the filtering, a condition is provided. All items matching this condition will pass the filter and will be part of the returned result.
The condition has mandatory to return a boolean outcome. In other words: The result of the condition has to be True or False.
|Values:||20,3,17,22,10,25,5||A collection of Numbers|
|Filter Condition:||x > 15||x is the item from values used for the check|
|Result:||20,17,22,25||the filtered numbers|
I - Input, P - Processing, O - Output
arrNumbersFiltered= arrNumbers.Where(Function (x) x > 15).ToArray()
(From x In arrNumbers Where x > 15 Select x).toArray
As mentioned above it is mandatory that the providing filter condition results with a boolean outcome. Similar what e.g. is done within the UiPath IF Activity inside the Condition block in the same manner the filter condition can be provided to the LINQ.
- x < 10 | item is less then 10
- x Mod 2 = 0 | filter for all even numbers
- Cdate(x).Date = Now.Date | for all today’s dates
- x.Trim() | is returning a string and not a boolean
- now.AddDays(1) | is returning a DateTime and not a boolean
Multiple conditions can be formulated by combining single conditions with the available conjunction operators
- x >= 5 AND x<= 10
- x.Equals(“ABC”) OR x.Contains(“A123”)
- IsNothing(row(“Name”) OrElse String.IsNullOrEmpty(row(“Name”).toString().Trim())
dtData.AsEnumerable.Where(Function (x) DateTime.TryParseExact(x("Date").toString.Trim, "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, nothing)).CopyToDataTable
(From fi In New DirectoryInfo("C:\_RPA\_Demo").GetFiles() Where Regex.IsMAtch(fi.Name,"\(\d+\)\.docx$", RegexOptions.IgnoreCase) Select fi.FullName).toArray
- with the WHERE operator items can be filtered
- The provided filter condition has to return a boolean
- condtions also can be combined by conjunction operators
For questions on your retrieval case open a new topic and get individual support