They are two ways u can choose,
Public Function IncrementStringNumber(ByVal strToChange As String) As String
Dim strNew As String
strNew = Left(strToChange, (Len(strToChange) - 4)) & CStr(Format(Val(Right(strToChange, 4)) + 1, "0000"))
IncrementStringNumber = strNew
Public Function Increment(ByVal value As String, ByVal incrementNumber As Integer) As String
Dim zeroString As String = Regex.Match(value, "^0+").Value
Dim numberString As String = Regex.Match(value, "[1-9]+").Value
'Dim numberString As String = Regex.Match(value, "[1-9][0-9]+").Value
Dim numberOFZero As Integer = zeroString.Length
Dim numberLength As Integer
Dim number As Integer = Int32.Parse(numberString)
number += incrementNumber
numberLength = number.ToString().Length
If numberOFZero + numberLength > value.Length Then
Dim numberToRemove As Integer = numberOFZero + numberLength - value.Length
If numberToRemove <= zeroString.Length Then
zeroString = zeroString.Substring(0, zeroString.Length - numberToRemove)
Else
zeroString = ""
End If
End If
Return zeroString + number.ToString()
No comments:
Post a Comment