Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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
Lua如何从字符串中删除撇号_Lua - Fatal编程技术网

Lua如何从字符串中删除撇号

Lua如何从字符串中删除撇号,lua,Lua,所以我对Lua gsub从字符串中删除撇号有一个问题,如果有一个撇号,或者有很多撇号,我似乎无法让它删除任何撇号 local uri_without_args = "'" --one on its own local uri_without_args = "''''''''lol''''" --in text local uri_without_args = "''''''''''''" --loads --etc--etc all occurrences must go local list

所以我对Lua gsub从字符串中删除撇号有一个问题,如果有一个撇号,或者有很多撇号,我似乎无法让它删除任何撇号

local uri_without_args = "'" --one on its own
local uri_without_args = "''''''''lol''''" --in text
local uri_without_args = "''''''''''''" --loads
--etc--etc all occurrences must go

local list = {
"%'", --apostrophe
}
for k,v in ipairs(list) do
    local uri_without_args_remove_duplicates, occurrences = uri_without_args:gsub(""..v.."","")
    if occurrences > 0 then
    occurrences = occurrences + 1
        for i=1, occurrences do
            if uri_without_args_remove_duplicates=="" then
                --do nothing
            else
                uri_without_args = uri_without_args:gsub(""..v.."","")
            end
        end
    end
end


print(uri_without_args)

只有当
uri\u(不带参数)
不为空时,才能为
uri\u(不带参数)
分配新值。如果您从分配给
uri\u而不带参数的
If
语句中删除
If
,或者如果
uri\u而不带参数的
“lol”
开头,那么它可以正常工作


正如Egor在评论中所说,您也可以简单地使用
uri\u(不带参数)\u remove\u duplicates
作为结果值。

唯一一次为
uri\u(不带参数)
指定新值的时候是
uri\u(不带参数)\u remove\u duplicates
不为空。如果您从分配给
uri\u而不带参数的
If
语句中删除
If
,或者如果
uri\u而不带参数的
“lol”
开头,那么它可以正常工作


正如Egor在评论中所说的,您也可以简单地使用
uri\u而不使用args\u remove\u duplicates
作为结果值。

您的变量
uri\u而不使用args\u remove\u duplicates
包含正确的结果,但您既不保存也不打印它。您的变量
uri\u而不使用args\u remove\u duplicates
包含正确的结果,但是您既没有保存也没有打印它。我按照建议删除了if语句,现在可以正常工作了谢谢:)我按照建议删除了if语句,现在可以正常工作了谢谢:)