i have array of string , want filtered array contains strings match searched string.
string[] myvalues = {"school.report1", "school.report2", "school.report3", "house.report1", "house.report2"}; string myfilter = "school"; string[] filteredvalues = myvalues.filter(myfilter); // or similar filteredvalues must contains only: "school.report1", "school.report2", "school.report3".
-- edit --
i prefer non-linq approach if possibile. otherwise know question can answered solution proposed here: filter array in c#.
if can't use linq can still use array.findall:
string[] filteredvalues = array.findall(myvalues, s => s.contains(myfilter)); or maybe want keep strings first token(separated dot) school:
string[] filteredvalues = array.findall(myvalues, s => s.split('.')[0] == myfilter);
Comments
Post a Comment