문제

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