【发布时间】:2018-08-24 00:54:12
【问题描述】:
因此,如果 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_without_args_remove_duplicates包含正确的结果,但您既没有保存也没有打印。
标签: lua