将这两个 lua 格式行合并为一个

combining these two lua formatting lines into one

有什么方法可以将最后两行格式化代码合并为一个吗?

str = "1, 2, 3, 4, 5, "

str = str:gsub("%p", {[","] = " >" }) -- replaces ',' with '>'
str = string.sub(str, 1, #str - 2) --removes last whitespace + comma

提前致谢:)

str = "1, 2, 3, 4, 5, "
str = str:sub(1, #str-2):gsub("%p", {[","] = " >" }) 

这会做你想做的事。

不过 Egor 的更优雅一些:

str = str:gsub(',',' > '):sub(1,-3)