str = "This is some text containing the word tiger."
if string.match(str, "tiger") then
print ("The word tiger was found.")
else
print ("The word tiger was not found.")
How to check if the text is found somewhere in the string?
string.find()
. In addition, you need to specify the end of the if-else statement. So, the actual code will be as follows:
str = "This is some text containing the word tiger."
if string.match(str, " tiger") then
print ("The word tiger was found.")
else
print ("The word tiger was not found.")
end
< p>or
str = "This is some text containing the word tiger."
if string.find(str, "tiger") then
print ("The word tiger was found.")
else
print ("The word tiger was not found.")
end
< p>If at least one specific matching text is found in the text string, I need to make the condition true, for example:
str = "This is some text containing the word tiger."
if string.match(str, "tiger") then
print ("The word tiger was found.")
else
print ("The word tiger was not found.")
How to check if the text is found somewhere in the string?
You can use string.match or string.find. I personally use string.find()
. In addition, you need to specify the end of the if-else statement. So, the actual code will be as follows:
str = "This is some text containing the word tiger."
if string.match(str, " tiger") then
print ("The word tiger was found.")
else
print ("The word tiger was not found.")
end
< p>or
str = "This is some text containing the word tiger."
if string.find(str, "tiger") then
print ("The word tiger was found.")
else
print ("The word tiger was not found.")
end
p>