How to check if a string contains a word

Asked

Viewed 716 times

-2

I wanted to know how to verify if a string exists a word, for example, I have two conditions for a situation the professional string can contain Medico or Paisanamedico. I wanted a north or way to check if the string "professional" contains "Pasaina", below an example of what I imagined

local profissao = GetUserJob(user)
if profissao has "Paisana" then
 print("funcionario fora de serviço")
else
 print("funcionario em servico")
end
  • 1

    This is Javascript?

  • 2

    Because three languages were placed ???

  • 1

    Specify your problem more clearly, put only related technologies.

  • pq whatever if the answer is in any of these languages, I just wanted a north...

2 answers

0

Look, you can put your sentence in a variable to check it later...

let profissao = 'Meu texto aqui contém paisana';

then Voce creates a variable for response, together checking the word with .includes

let result = profissao.includes('paisana');

includes this checking if there is the word 'paisana' within the professional variable

let profissao = 'Meu texto aqui contém paisana';
let result = profissao.includes('paisana');

console.log(result);

then just check if the answer is true or false.

if (profissao)
   //codigo

it returns (true), the word plainclothes exists within the professional variable.

to change the status, just update the professional variable that does not contain the word paisana. I hope to have helped.

-2


Browser other questions tagged

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