I have a char array with a length of 4. I am attempting to create a way to add 1 to this char array and produce a string "0002".
I can convert the char array to an integer in order to add 1 to it, but the issue is I am losing the leading zeros in the process. Is there a way to preserve the zeros in the addition?
Some examples of output I want.. if endCode is "0009" and I add 1, I want "0010" if endCode is "0999" and I add 1, I want "1000"
I am losing the zeros with my current code..
(Convert.ToInt32(New String(endCode)) + j).ToString
You're so close. Only 5 characters short. You just need a format string:
(Convert.ToInt32(New String(endCode)) + j).ToString("D4")
Though one wonders why or how this data came to be a character array in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With