Вопрос

I would like to use string.gsub to search through a phone number field and remove any "-" or spaces.

Is there any way to combine the two statements I have below into one?

local phonenumber = string.gsub("123-123-1234", "-", "")
phonenumber = string.gsub(phonenumber , " ", "")
Это было полезно?

Решение

Yes. The square brackets are used to group multiple elements in Lua patterns

local phonenumber = string.gsub("123-123 -1234", "[- ]", "")
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top