5
I am creating a routine to search reserved words in a text (name of people). I have tested with Contains()
and IndexOf()
. Works well most of the time. However in some words the return does not satisfy. Example: in the name CORALLINE returns the reserved word ORAL.
Below the code performed:
public JsonResult GetPalavrasReservada1(string frase)
{
var palavras = db.TBL_PALAVRA_RESERVADA.Where(pal => pal.PLR_ATIVO == 0).Select(i => new {i.PLR_DESC}).ToList();
var palavrareservada = "";
for (int i = 0; i < palavras.Count; i++)
{
if (frase.ToUpper().Contains(palavras[i].PLR_DESC.ToString()))
{
return Json(palavras[i].PLR_DESC.ToString());
}
}
return Json(palavrareservada);
}
I’m using wrong logic or methods?
And isn’t that right? In fact the name "Coralina" contains the word "oral".
– Jéf Bueno
@LINQ does not agree with the definition of word adopted here. You are thinking of substring, here a word is a properly delimited token. Since "coralline" forms a single token, it does not contain "oral"
– Jefferson Quesado
Wouldn’t be the case to check has blank space before and after the word?
– Felipe Avelar