我正在尝试计算并打印出“终止符”值已输出多少次的数值。有没有这样做的功能?如果不是我应该如何解决这个问题?
output = get_application_name()
var = string.match("terminator", get_application_name())
print(var)
我想数
nil
terminator
nil
nil
terminaor
我正在尝试计算并打印出“终止符”值已输出多少次的数值。有没有这样做的功能?如果不是我应该如何解决这个问题?
output = get_application_name()
var = string.match("terminator", get_application_name())
print(var)
我想数
nil
terminator
nil
nil
terminaor
您可以使用该string.gsub
功能。从文档:
gsub
还返回发生的匹配总数作为其第二个值。
所以:
output = get_application_name()
_, count = output:gsub("terminator", '')
print(output)