Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 在Lua中,如何在url中查找特定字符串?_String_Url_Lua - Fatal编程技术网

String 在Lua中,如何在url中查找特定字符串?

String 在Lua中,如何在url中查找特定字符串?,string,url,lua,String,Url,Lua,我正在编写一个Lua函数,如果url有特定字符串,例如“home”,我想添加一个if/else语句,如果url如下所示: http://AAA/home http://AAA/home/01 http://AAA/home/02 然后停止该函数,但如果url没有“home”字符串,则执行该函数: http://AAA/next http://AAA/test 有人能给我一些关于在url中检测特定字符串的线索吗?有两种方法可以做到这一点: 您可以使用string.match()或string.

我正在编写一个Lua函数,如果url有特定字符串,例如“home”,我想添加一个if/else语句,如果url如下所示:

http://AAA/home
http://AAA/home/01
http://AAA/home/02
然后停止该函数,但如果url没有“home”字符串,则执行该函数:

http://AAA/next
http://AAA/test

有人能给我一些关于在url中检测特定字符串的线索吗?

有两种方法可以做到这一点: 您可以使用
string.match()
string.find()
,我个人使用
string.find()
(大多数人使用)

您的代码如下所示:

http://AAA/home
http://AAA/home/01
http://AAA/home/02
text=”http://AAA/home"
如果string.find(文本“home?”,0,true),则
#做你想做的
其他的
#做点别的

结束
无论何时使用string.find,请注意搜索的字符串是一个正则表达式-因此搜索“home?”也将匹配“hom”。为了避免这种情况,请使用string.find(文本“home?”,0,true)表示它是一个普通字符串