I need to make a check with a given text within a string
.
How do I go through this string and look up the text to do this check?
Example:
If(dentro da string contém "Olá")
{
Mostre o valor determinado para essa string;
}
I need to make a check with a given text within a string
.
How do I go through this string and look up the text to do this check?
Example:
If(dentro da string contém "Olá")
{
Mostre o valor determinado para essa string;
}
Use the Contains()
method to see if a text is present inside another:
if ("Olá Mundo".Contains("Olá")) {
//Faça o que quer aqui
}
string suaString = "Olá mundo";
if (suaString.Contains("Olá") == true)
{
Console.Write("A string contain 'Olá' ");
}
Since the Contains () method returns a Boolean and was used inside an IF you do not need to be validating with suaString.Contains("Olá") == true
, I did so just to make it easier to understand, so we usually do this:
string suaString = "Olá mundo";
if (suaString.Contains("Olá"))
{
Console.Write("A string contém 'Olá' ");
}