If no search by value

Asked

Viewed 75 times

-3

There is a snippet in my program that looks for a specific string to assign a value to some variable. However I am not able to run these parameters inside the "If"... Debugging goes through this.

//if (valor == "Datasul")
                    if (valor.Contains("Datasul"))
                    {
                        t1.ObsRecurso = model.ObsDatasul;
                    }
                    else if (valor.Contains("Protheus"))
                    {
                        t1.ObsRecurso = model.ObsProtheus;
                    }
                    else
                    {
                        t1.ObsRecurso = "";
                    }

                    ListaRecursos.Add(t1);

                }

I tried to do this search so much with if (valor == "Datasul") how much valor.Contains("Datasul")), but in none of the cases the program enters this conditional.

@EDIT

inserir a descrição da imagem aqui

  • Tried to use Equals?

  • if (valor.Equals("Datasul"))

  • Hudson, what is the value of the variable valor?

  • @Viana In C# it makes no difference unless the operator/method is rewritten.

  • @LINQ The variable is returning the correct value. I edited the post with an illustrative GIF.

1 answer

1

Hudson, check if it works as follows:

valor.ToUpper().Trim().Contains("PROTHEUS")

Or

valor.ToUpper().Trim().Equals("PROTHEUS")

Otherwise, check if this string actually has the current value, debugging or logging.

  • I have had no success in either way. It simply does not execute the conditional. https://i.imgur.com/g1JsY95.gif

  • With contains also did not work?

  • No. Neither of the two ways worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.