Strings - Filling In Leading Zeros Wtih A Zero

Posted by headscratch on Stack Overflow See other posts from Stack Overflow or by headscratch
Published on 2011-01-13T22:33:34Z Indexed on 2011/01/13 22:54 UTC
Read the original article Hit count: 143

Filed under:
|

I'm reading an array of hard-coded strings of numeric characters - all positions are filled with a character, even for the leading zeros. Thus, can confidently parse it using substring(start, end) to convert to numeric.

Example: "0123 0456 0789"

However, a string coming from a database does not fill in the leading zero with a 'zero character', it simply fetches the '123 456 789', which is correct for an arithmetic number but not for my needs and makes for parsing trouble.

Before writing conditionals to check for leading zeros and adding them to the string if needed, is there a simple way of specifying they be filled with a character ? I'm not finding this in my Java book...

I could have done the three conditionals in the time it took to post this but, this is more about 'education'...

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about string-manipulation