Tags: 00000234-345, essentials, format, guysi, java, leading, string, zeros

How to remove leading Zeros from a String

On Java Studio » Java Essentials

2,187 words with 5 Comments; publish: Sun, 23 Sep 2007 07:34:00 GMT; (15078.13, « »)

Hey guys

i have to remove leading zeros from a string and String is in this format "00000234-345"

if there is no - sign in the string i can just convert the string to Integer and all the zreos are removed. because of - sign i cant do that. so can anyone help me in this?

Thanks

sam

All Comments

Leave a comment...

  • 5 Comments
    • Loop over the string starting at the beginning until you find a non-zero (or hit the end of the string). Save the index of where you left off. Call substring on the original to get it. Can't you figure that out?
      #1; Mon, 09 Jul 2007 20:06:00 GMT
    • java test 000121334-412341234

      121334-412341234

      java test 000121231asidiasda

      121231asidiasda

      java test 0000000000

      public class test {

      public static void main(String[] args) {

      System.out.println(args[0].replaceAll("^0*",""));

      }

      }

      #2; Mon, 09 Jul 2007 20:06:00 GMT
    • > java test 000121334-412341234

      > 121334-412341234

      >

      > java test 000121231asidiasda

      > 121231asidiasda

      >

      > java test 0000000000

      >

      > > public class test {

      > public static void main(String[] args) {

      >

      >

      >

      >

      >

      >System.out.println(args[0].replaceAll("^0*",""));

      > }

      > }

      >

      Thanks for doing his homework for him. Now he doesn't have to think.

      #3; Mon, 09 Jul 2007 20:06:00 GMT
    • Or it is luring him to use a prefabricated method instead of doing some elementary programmaing along your lines and profiting from it. I don't know.
      #4; Mon, 09 Jul 2007 20:06:00 GMT
    • Thanks guys Appreciate your help
      #5; Mon, 09 Jul 2007 20:06:00 GMT