Archive for December, 2011


How to Remove Leading Zero

I have string ’00709′ and I want to remove leading zero and have a result like this: ’709′.

In java, to do this you can try this method:

public String removeLeadingZero(String s){
 return s.replaceFirst("^0+(?!$)", "");
}

If you have string ’0.000709′, it will be like this: ‘.000709′.

Just try it :mrgreen:

When I try to run another program from Java, well I think Java can do that. So I try to google it. Then I found interesting web site: http://mindprod.com/jgloss/exec.html

In summary, you can use this command to Run another program:

Runtime.getRuntime().exec("cmd");
// or
Runtime.getRuntime().exec("notepad");
// or
Runtime.getRuntime().exec("C:\\Temp");

Note that exec() can only run *.exe. If you want to run *.bat file, here is the example:

Runtime.getRuntime().exec("cmd /c \"C:\\Temp\\test.bat\"");

Interesting huh? Lest try :mrgreen:

Follow

Get every new post delivered to your Inbox.