I have an application that performs a search in the database according to a parameter (text box), the problem is that I want to omit the searches with words S.A de C.V
, sa de cv
, s.a. de
etc.
To do that, make a small function that checks if the string contains a certain word, the detail is that I have to do a lot of checks...
Is there a way to carry out this process without so many comparisons?
public bool cadenaValida(string strCadena)
{
bool bolvalor;
if (strCadena.Contains("%") || strCadena.Contains("sa de cv") || strCadena.Contains("SA de CV") || strCadena.Contains("S.A. de C.V."))
bolvalor = false;
else
bolvalor = true;
return bolvalor;
}
The simplest thing you can do is declare a list with the words you want to search for, iterate said list and validate one by one that the value of the list is contained in your input string, in the first value found the cycle is broken and it will return a
true
.