如何格式化带有前导零的Java字符串? [英] How to format a Java string with leading zero?
本文介绍了如何格式化带有前导零的Java字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是字符串,例如:
"Apple"
我想添加零来填充 8 个字符:
and I would like to add zero to fill in 8 chars:
"000Apple"
我该怎么做?
推荐答案
如果你不得不在没有图书馆帮助的情况下完成:
In case you have to do it without the help of a library:
("00000000" + "Apple").substring("Apple".length())
(有效,只要您的字符串不超过 8 个字符.)
(Works, as long as your String isn't longer than 8 chars.)
这篇关于如何格式化带有前导零的Java字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文