-
Dim a As String = "TW000001"
-
Dim b As String = Microsoft.VisualBasic.Left(a, Len(a) - 1)
-
Dim c As Integer = CInt(Microsoft.VisualBasic.Right(a, 1))
-
c = c + 1
-
Dim d As String = b + c.ToString
You can modify this code to compensate for 2, 3, or 4 digit number by looking for the last instance of zero. Or just chop TW and fill in the leading zeros. Hope this gets you started.
Although this solution may work, I would suggest using code that is a bit more flexible for your situation.
What you really want to do is trim the "TW" off of your number, convert the number (which is a currently a String) into an Integer, add that integer to some value, and then put the whole thing back together with your number formatted in such a way that it shows 6 digits and starts with "TW".
The following code will do that for you:
-
Dim additionNumber As Integer = 1
-
Dim originalStr As String = "TW000001"
-
'grabbing 000001, which starts at index 2 (vb) in the String
-
Dim numberStr As String = originalStr .Substring(2)
-
Try
-
Dim myNumber As Integer =Integer.Parse(numberStr)
-
Dim newNumber As Integer = additionNumber + myNumber
-
'The following line will format the newNumber to show 6 digits at all times
-
'If the number is less than 6 digits, the number is padded with 0s to its left
-
'The newString will then hold "TW" + a number that is 6 digits long
-
Dim newString As String = "TW" + newNumber.ToString.PadLeft(6, "0")
-
Catch ex As Exception
-
'couldn't create a number based on the string provided to Integer.Parse()
-
End Try
-
Enjoy!
-Frinny