【发布时间】:2020-08-15 05:04:57
【问题描述】:
我想替换myString = "This is __an example__, it's the coolest thing ever!"
我想用<span style="bla bla bla">替换第一个__,用</span>替换第二个
我不知道该怎么做...
【问题讨论】:
我想替换myString = "This is __an example__, it's the coolest thing ever!"
我想用<span style="bla bla bla">替换第一个__,用</span>替换第二个
我不知道该怎么做...
【问题讨论】:
也试试这个代码:
myString = "This is __an example__, it's the coolest thing ever!"
myString = myString:gsub("__(.-)__", "<span style='bla bla bla'>%1</span>")
【讨论】:
__TEXT__ 的多个“实例”,或者最大限制也是 1
gsub 表示全局替换,因此它适用于所有实例。要限制为第一个实例,请在通话结束时添加 ,1,如 Rithik 的回答中所述。
__ 替换为x,将第二个__ 替换为y,但我想不止一次这样做
__THIS IS A SPAN__ and this is not, while __THIS IS ANOTHER SPAN__ and this is not, again!,明白了吗?
试试:
myString = "This is __an example__, it's the coolest thing ever!"
myString = myString:gsub("__", "<span style='bla bla bla'>",1)
myString = myString:gsub("__", "</span>",1)
【讨论】: