Hi,
I would not rely on numeric types for this job, just operate on characters:
- use three state variables: bool carry (initially false), bool insideFirstNumber (initially false), and int countNumbers (initially zero);
- scan the string right to left;
- while finding digits:
- if insideFirstNumber is false, set carry true, increment countNumbers,
and if it was zero, then and only then set insideFirstNumber true;
- if insideFirstNumber and carry both true, emit incremented digit and clear carry,
unless it was a "9", then emit "0" and set carry true;
- otherwise just copy the digit.
- while finding non-digits but also when reaching start of string:
- clear insideFirstNumber;
-if carry is true, emit a "1" (number gets extra digit e.g. 99 -> 100) and clear carry;
- copy the non-digit (not at start of string!).
All this would take about 20 lines of code, nothing fancy, no LINQ, no lambdas, just one StringBuilder object.
:)
PS: the above would turn A02540a into A02541a; if you really want to get A02540a1, then small adjustments are required, things become even simpler, as now insideFirstNumber and carry would initially be true, and countNumbers would not be needed at all.