Marek
Marek

Reputation: 119

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?

Upvotes: 5

Views: 4782

Answers (3)

Bernardo Ramos
Bernardo Ramos

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

daurnimator
daurnimator

Reputation: 4311

You can strip leading zeros with string operations. e.g.:

x = x:match("0*(%d+)")

Upvotes: 1

Marek
Marek

Reputation: 119

Done... It was simple...

join = string.format("%u", join);

Upvotes: 0

Related Questions