I want to remove all spaces from a string in Lua. This is what I have tried:
string.gsub(str, "", "")
string.gsub(str, "% ", "")
string.gsub(str, "%s*", "")
This does not seem to work. How can I remove all of the spaces?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It works, you just have to assign the actual result/return value. Use one of the following variations:
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).