如何检查Lua中字符串中是否找到匹配的文本?
发布时间:2020-12-15 00:22:27 所属栏目:大数据 来源:网络整理
导读:如果在文本字符串中至少找到一个特定的匹配文本,我需要使条件为真,例如: 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.") 如
如果在文本字符串中至少找到一个特定的匹配文本,我需要使条件为真,例如:
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.") 如何检查文本是否在字符串中的某处找到? 解决方法
你可以使用string.match或string.find。我个人自己使用
string.find() 。此外,您需要指定if-else语句的结尾。所以,实际的代码将如下:
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 要么 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |