Fix Lua Format String Error : Illegal Escape Character

0, problem description

invalid option '%{' to 'format'
invalid option '%;' to 'format'

This is the problem I've had with escaping CSS, but you might also:

invalid option '% (extra characters here)' to 'format'

similar error.

1. Solution

For a list of legal escape characters, refer to:

Lua string
https://www.runoob.com/lua/lua-strings.html

Therefore, this error will be reported when executing string.format() when it encounters % (text or symbol that is not an escape character).

Therefore, if a non-escaped character is added by mistake, it should be deleted;

If you need to enter a percent sign (%), it should be escaped:

Original: %
escape: %%

If the legal escape character is judged to be illegal, it is recommended to delete it and type it again with the keyboard:

Original character: %О (Note, this is Russian instead of 0)
Re-enter: %0 (this is the number 0)

Because the code copied from the Internet may contain inexplicable invisible characters or minor language symbols, which look exactly like real escape characters.

Fix Lua Format String Error : Illegal Escape Character

https://blog.tsinbei.com/en/archives/741/

Author
Hsukqi Lee
Posted on

2023-06-22

Edited on

2023-06-22

Licensed under

CC BY-NC-ND 4.0

Comments

Name
Mail
Site
None yet