Alamin Aji Alamin Aji - 1 month ago 8
Java Question

Remove leading zeros from a number in a string

I wanna trim this string.

"0000819780"

How i can get just the "819780" part.

I can do it with my way, just curious is there any "elegant" or "right" way to do this.

Answer

I hope this works:

   try {
   int i=Integer.parseInt(yourString)
   System.out.println(i);
   }catch(Exception e)
   {//String has something more than number
    }