Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Format 00001 number

For example, I get the input number LP00001, LP00023, LP00010 in text format. How can I get a number (1, 23, 10) based on the data received, add one, and form, for example, LP00002, LP00024, LP00011?

System.out.printf("%s%05d%n", "LP", i);

it suits me, I don’t understand how I can extract the number itself

I need a number that is for example in LP00032, that is, in fact I should get 32

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If LP is a pattern (always 2 characters at the begining of the string), you could do this:

String text = "LP00001";
int numericValue = Integer.parseInt(text.substring(2)) + 1;
System.out.printf("%s%05d%n", "LP", numericValue);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading