本文介绍了如何用前导零格式化Java字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

 Apple

我想加上零填写8个字符:

 000Apple

我该怎么做?
code>(00000000+Apple)。substring(Apple.length())

(工作,只要你的字符串不超过8个字符。)


Here is the String, for example:

"Apple"

and I would like to add zero to fill in 8 chars:

"000Apple"

How can I do so?

解决方案

In case you have to do it without the help of a library:

("00000000" + "Apple").substring("Apple".length())

(Works, as long as your String isn't longer than 8 chars.)

这篇关于如何用前导零格式化Java字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 15:37