regex to strip leading zeros treated as string

后端 未结 6 1269
灰色年华
灰色年华 2020-12-30 04:28

I have numbers like this that need leading zero\'s removed.

Here is what I need:

00000004334300343 -> 4334300343

000

6条回答
  •  时光说笑
    2020-12-30 05:17

    If you know input strings are all containing digits then you can do:

    String s = "00000004334300343";
    System.out.println(Long.valueOf(s));
    // 4334300343
    

    Code Demo

    By converting to Long it will automatically strip off all leading zeroes.

提交回复
热议问题