'Searching for Specifc String in Array in LINQ
example of string array stored in DB = "SA|IL|RC|AL|IN" per residence
User can search on specific option
allResidence = allResidence.Where(x => x.LivingOptions.Split('|', StringSplitOptions.RemoveEmptyEntries).Contains(searchCriteria.LivingOptionCode));
this causes an issue if user searches on I - i want it to return 0 but using Contains will obviously return IL & IN as valid options
so how to split and check for specific entry
tried using Equals
allResidence = allResidence.Where(x => x.LivingOptions.Split('|', StringSplitOptions.RemoveEmptyEntries).Equals(searchCriteria.LivingOptionCode));
but that returns 0 when searching for IL example
Solution 1:[1]
answer provided by @DemetriusAxenowski
allResidence = allResidence.Where(x => x.LivingOptions.Split('|', StringSplitOptions.RemoveEmptyEntries).Any(x => x == searchCriteria.LivingOptionCode))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Craig |
