How to Remove the Leading Zeroes From a Text String
- 1). Type the following code in Ruby to remove leading zeroes from a number saved as a string, assuming your string is assigned to the variable "@t": @t.to_i.to_s. Use this code if your string contains letters: @t.gsub!(/^0{n}+/,'').
- 2). Enter the following code to strip leading zeroes from a string in Python, assuming your string is "mystring": mystring = mystring.lstrip('0').
- 3). Use the following code to trim leading zeroes from a string in C++, assuming your string is "t": string b = t.TrimStart('0');. This gives you a string "b" without the leading zeroes.
Source...