How do I check if a matching text is found in the string in Lua?

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>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

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3270 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.