I have a string which i need to increment by 1.
The string layout i have is as follows "MD00494"
How would i increment this to "MD00496"
If it was a normal string witn numbers id parse it to a int. But with letters how do i do this.
Increment a String with numbers and letters
Page 1 of 12 Replies - 132 Views - Last Post: 07 March 2013 - 07:22 AM
Replies To: Increment a String with numbers and letters
#2
Re: Increment a String with numbers and letters
Posted 07 March 2013 - 05:02 AM
.SubString the last 5 letters and the first two to get the id and the number by themselves. Then you can int.Parse the number, increment it, then add it back to the id to get your result.
#3
Re: Increment a String with numbers and letters
Posted 07 March 2013 - 07:22 AM
I find that if you trying to increment strings, it is a sign of a bad design.
A better way is to create a class that encapsulate that functionality. You then have the option to override the .ToString function method, to return the full ID string.
A better way is to create a class that encapsulate that functionality. You then have the option to override the .ToString function method, to return the full ID string.
Spoiler
This post has been edited by AdamSpeight2008: 07 March 2013 - 07:25 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|