How to remove spaces from a string in Lua?

It works, you just have to assign the actual result/return value. Use one of the following variations:

str = str:gsub("%s+", "")
str = string.gsub(str, "%s+", "")

I use %s+ as there’s no point in replacing an empty match (i.e. there’s no space). This just doesn’t make any sense, so I look for at least one space character (using the + quantifier).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)