2

I want to generate a sequence number starting from 00000001,00000002....(i need all these zero as well)Please help me..Thanks in advance..

vignesh
  • 1,573
  • 7
  • 33
  • 60
  • None of the answer are from XSLT, and you've accepted one. Retagging –  Mar 22 '11 at 23:18

3 Answers3

7

You can just generate the sequence numbers as integers and then format them like this:

String.format("%08d", yournumber);

See this question: How can I pad an integers with zeros on the left?

Community
  • 1
  • 1
Kai G
  • 3,371
  • 3
  • 26
  • 30
2

You just need to use string formatting to pad numbers with zeros:

for (int i = 1; i < 1000; i++) {
    String sequence = String.format("%08d", i);
}
WhiteFang34
  • 70,765
  • 18
  • 106
  • 111
2

You can just maintain that variable as an integer and use String.format to format it.

String s = String.format ("%08d", 42); // gives you "00000042"
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953