这是我的密码
local function char(...) return string.char(...) end
local function addtok(text,token,C)
text = text or ""
local string = ""
local count = 0
for word in text:gmatch(("[^%s]+"):format(char(C))) do
string = string..char(C)..word
end
string = string..char(C)..token
print(string)
end功能
addtok("Devotion Aura;Charger;Righteous Fury","Seal of Wisdom",59)返回
;虔诚之灵;充电器;正义之怒;智慧之印
但我想要的是
虔诚之灵;充电器;正义之怒;智慧之印
可能的修正:print(string.sub(string, 2))
有更好的解决办法吗?
发布于 2022-02-28 18:53:46
local function addtok(text,token,C)
local string = (text or "").. string.char(C) .. token
print(string)
end
addtok("Devotion Aura;Charger;Righteous Fury","Seal of Wisdom",59)发布于 2022-02-28 18:22:11
行string = string..char(C)..word将放在第一个分号的前面。这就是在循环中追加的问题--如果不想使用尾随或前导分隔符,则必须为最后一个或第一个元素设置一个异常。但是,在这种情况下,您应该使用table.concat,这既可以提高性能(避免不必要的字符串副本),也可以方便地使用分隔符:
local function char(...) return string.char(...) end
local function addtok(text,token,C)
text = text or ""
local words = {}
local count = 0
for word in text:gmatch(("[^%s]+"):format(char(C))) do
table.insert(words, word)
end
local string = table.concat(words, char(C))..char(C)..token
print(string)
endhttps://stackoverflow.com/questions/71299112
复制相似问题