0
I created a search method that receives a text, and searches that text in a ObservableCollection
pre-filled.
private void btn_Pesquisar_Click(object sender, RoutedEventArgs e)
{
ObservableCollection<object> temp = null;
string oTexto_Pesquisa = txt_Pesquisa.Text.ToLower();
Regex rgx = new Regex("[^a-zA-Z0-9 -]");
oTexto_Pesquisa = rgx.Replace(oTexto_Pesquisa, "");
/*Procurando Marcas*/
if (WhereToSearch.Equals("Marcas"))
{
temp = new ObservableCollection<object>();
foreach (Marcas marcas in obs_Marcas)
{
if (marcas.Nome.ToLower().Contains(oTexto_Pesquisa) || marcas.Descricao == null ? true : marcas.Descricao.ToLower().Contains(oTexto_Pesquisa))
{
temp.Add(new Marcas
{
Nome = marcas.Nome,
Imagem = marcas.Imagem,
Descricao = marcas.Descricao
});
}
}
Lista_Marcas.ItemsSource = temp;
}
When searching, it is returned the records within this ObservableCollection
.
But there’s a problem with the regex
;
For example, when searching for "as" the "UTAS" record is returned. But when searching "as-", it was expected to return the "AS-Val" record but no record is returned and there is no error.
How to solve this survey?
Hello @Marceloawq. It would be interesting for you to complement your question by posting some product descriptions from your list
obs_Marcas
, indicating which items should be listed but are not listed.– Jônatas Hudler
@Jonathan shudler, I’ve edited the question
– Marceloawq
@Marceloawq please put an input example and what you want regex to return
– Paz
I cannot reproduce it -> http://rextester.com/HIRT9019
– Mariano