'Remove leading zeroes in Lua string
I have number string of 6 digits but sometimes I become number with leading zeroes, how can I simple and handily remove that leading zeroes in Lua?
Solution 1:[1]
You can strip leading zeros with string operations. e.g.:
x = x:match("0*(%d+)")
Solution 2:[2]
Done... It was simple...
join = string.format("%u", join);
Solution 3:[3]
This one appears to work also for empty strings, string without leading zeros, etc:
x = string.gsub(x, '0*', '', 1)
or
x = x:gsub('0*', '', 1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | daurnimator |
| Solution 2 | Mihai Caracostea |
| Solution 3 | Bernardo Ramos |
