string Lua 字符串替换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4297655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 00:53:44 来源:igfitidea点击:
Lua String replace
提问by Frank
How would i do this?
我该怎么做?
I got this:
我懂了:
name = "^aH^ai" string.gsub(name, "^a", "")
which should return "Hi", but it grabs the caret character as a pattern character
应该返回“Hi”,但它将插入字符作为模式字符抓取
What would be a work around for this? (must be done in gsub)
有什么办法可以解决这个问题?(必须在 gsub 中完成)
回答by Kknd
Try:
尝试:
name = "^aH^ai"
name = name:gsub("%^a", "")