Java-code --
String value = 00008, increment something like 00008 to 00009.
If anyone can help me here I'd greatly appreciate it, thanks!
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Java-code --
String value = 00008, increment something like 00008 to 00009.
If anyone can help me here I'd greatly appreciate it, thanks!
Are you sure you really want to increment a String? The reason I ask is that if you are continually wanting to increment an integer value associated with a String it might make more sense to have an int variable and increment that.
If you really have a String and want to produce another string associated with the incremented value: use Integer.parseInt() to obtain the integer value, increment that value, and finally produce the new String with String.format().
The last step will involve something like String.format("%05d",val) but check the documentation linked to for details about the format string.
Code is something like..
String s = "00008";
int i =Integer.parseInt(s);
System.out.println("i.."+i); // 8
String s1 = String.format("%05d",i);
System.out.println("s1......."+s1); // 00008
How to increment results = s1+1 ; ?
String.format("%05d",i);
--->
String.format("%05d", i + 1);
... ?
raghu3.ankam (May 24th, 2013)
thanks..