[英]is there a way that works , to change spaces in a string to underscore?
function exists(f)
filetry=""
local fileBuffer={}
for w in x:gmatch("%S+") do
table.insert(fileBuffer,w)
end
for i, v in ipairs(fileBuffer) do
filetry=filetry.."_"..v
end
f=filetry
if os.execute("test -e "..f) == true then
return true
else
return false
end
end
i need to change space characters to underscore so i can find the file in termanal i have tried to use apis but it's not working for me due to my computer deletes it after install it. 我需要将空格字符更改为下划线,以便我可以在termanal中找到该文件我尝试使用api但由于我的计算机在安装后将其删除,因此它无效。 so i just need a function that can make spaces , underscore and ,use the termanal test command to find a file 所以我只需要一个可以创建空格,下划线的函数,并使用termanal test命令查找文件
str = str:gsub("%s+", "_")
-- where `str` is the string you want to remove the spaces from.
-- Replaces multiple consecutive space characters with single _.
-- Remove the `+` to make it replace each space character with its own _.
Example: 例:
print( ("Hello world"):gsub("%s+", "_") )
-- will print "Hello_world"
EDIT: Note that string.gsub() creates a new string instead of modifying the old one, which is why in my first example the reasignation str = str:gsub...
was necessary. 编辑:请注意string.gsub()创建一个新的字符串而不是修改旧的字符串,这就是为什么在我的第一个例子中重新签名str = str:gsub...
是必要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.