开发者

Cannot use Percent (%) in a Lua pattern

I have this line in a Lua script that crash my software every time:

fm开发者_C百科t_url_map = string.gsub( fmt_url_map, '%2F','/' )

I want to replace all occurrences of %2F occurrences in a text to /. If I remove the % , it doesn't crash.

What am I doing wrong ?


% is a special symbol in Lua patterns. It's used to represent certain sets of characters, (called character classes). For example, %a represents any letter. If you want to literally match % you need to use %%. See this section of the Lua Reference Manual for more information. I suspect you're running into problems because %F is not a character class.


You need to escape the '%' with another '%'

fmt_url_map = string.gsub( fmt_url_map, '%%2F','/' )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜