fork download
  1. using static System.Console;
  2. using System.Linq;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. var txtFiltro = "noiva,unhas";
  7. var lista = new[] {
  8. new{Nome_Grupo = "Noivas de Plantão"},
  9. new{Nome_Grupo = "Noivas 2016/ 2017 - RJ"},
  10. new{Nome_Grupo = "Noivas Goianas"},
  11. new{Nome_Grupo = "NOIVA FELIZ-Compra,venda e troca de acessórios e vestidos de noivas."},
  12. new{Nome_Grupo = "DEUS ACIMA DE TUDO"},
  13. new{Nome_Grupo = "No Colo De Nossa Senhora"},
  14. new{Nome_Grupo = "Aqui tem uma frase com unhas"},
  15. };
  16. var palavrasFiltro = txtFiltro.ToLower().Split(',');
  17. var matches = lista.Where(x => !x.Nome_Grupo.ToLower().ContainsAny(palavrasFiltro)).ToList();
  18. matches.ForEach(WriteLine);
  19. }
  20. }
  21.  
  22. public static class StringExt {
  23. public static bool ContainsAny(this string haystack, params string[] needles) {
  24. char[] separators = { '\n', ',', '.', ' ' }; //isto é ingênuo, precisa ver tudo o que pode indicar fim de frase
  25. var words = haystack.Split(separators);
  26. foreach (var word in words) {
  27. foreach (var needle in needles) {
  28. if (word == needle) return true;
  29. }
  30. }
  31. return false;
  32. }
  33. }
  34.  
  35. //https://pt.stackoverflow.com/q/128150/101
Success #stdin #stdout 0.02s 17376KB
stdin
Standard input is empty
stdout
{ Nome_Grupo = Noivas de Plantão }
{ Nome_Grupo = Noivas 2016/ 2017 - RJ }
{ Nome_Grupo = Noivas Goianas }
{ Nome_Grupo = DEUS ACIMA DE TUDO }
{ Nome_Grupo = No Colo De Nossa Senhora }