Adding 0's to string/int variable

前端 未结 3 829
遥遥无期
遥遥无期 2021-01-15 08:42

So I have been working on a naming convention which add 0\'s before a string. I\'m trying to do this the short handed way before breaking everything into if statements. Here

3条回答
  •  抹茶落季
    2021-01-15 08:51

    Assuming that n is a String that represents a number, or more generally that n doesn't have any space characters:

    String.format("%5s",n).replace(" ","0");
    

提交回复
热议问题