Reputation: 119
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?
Upvotes: 5
Views: 4782
Reputation: 4577
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)
Upvotes: 0
Reputation: 4311
You can strip leading zeros with string operations. e.g.:
x = x:match("0*(%d+)")
Upvotes: 1