mercredi 25 février 2015

vb.net increment string with with prefix

I'm sure this question has been asked before, but I can't find exactly what I'm after.


I have a string which has a string, then a dash, then a number, e.g. "TERM-01" which happens to be the name of an electrical terminal in a switchboard. I want to increment it to "TERM-02", "TERM-03" etc.


I have come up with this:



TermNo = CStr(Mid(TermNo, 1, InStr(TermNo, "-")) & (CInt(Mid(TermNo, InStr(TermNo, "-") + 1, TermNo.Length - InStr(TermNo, "-")) + 1)))


Which seems to work fairly well, however I need to increment the number including the 0, so 08, 09, 10 instead of 8,9,10.


Any ideas?


Aucun commentaire:

Enregistrer un commentaire