带连字符的 Lua string.gsub [英] Lua string.gsub with a hyphen
本文介绍了带连字符的 Lua string.gsub的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个字符串 - 每个字符串有很多行,如下所示:
I have two strings - each string has many lines like the following:
value_1 = "DEFAULT-VLAN"
value_2 = "WAN"
data = "HOSTNAME = DEFAULT-VLAN"
result = string.gsub(data,value_1,value_2)
print(result)
结果:
data = "HOSTNAME = DEFAULT-VLAN"
当连字符(-")从它正在工作的值中删除时.有没有简单的方法可以解决这个问题?
When the hyphen ("-") is deleted from the value it is working. Is there an easy way to solve this?
谢谢!
推荐答案
-
是 Lua 模式中的魔法字符.你需要逃避它.
-
is a magic character in Lua patterns. You need to escape it.
改变
value_1 = "DEFAULT-VLAN"
到:
value_1 = "DEFAULT%-VLAN"
这篇关于带连字符的 Lua string.gsub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文