Is there a way to check if a word is within a user-described phrase?
Ex:
palavra = "criativo";
Sentence written by the user:
"Eu sou criativo"
Is there a way to check if a word is within a user-described phrase?
Ex:
palavra = "criativo";
Sentence written by the user:
"Eu sou criativo"
You can use the Contains () .
string frase = "Eu sou criativo";
string palavra = "criativo";
if(frase.Contains(palavra))
{
faça algo;
}
Just to complement the response from @ Mathi901.
In addition to using Contains()
to validate yourself a string
exists within another, you can also use StartsWith()
"to verify that a string
starts with a given string
, or the EndsWith()
to check if it ends with given string
.
string frase = "eu sou criativo";
//Validar se contém "criativo"
if(frase.Contains("criativo")) { ... }
//Validar se começa com "criativo"
if(frase.StartsWith("criativo")) { ... }
//Validar se termina com "criativo"
if(frase.EndsWith("criativo")) { ... }