devxlogo

IncrementString- Incrementing the numeric right-most portion of a string

IncrementString- Incrementing the numeric right-most portion of a string

' Increment the numeric right-most portion of a string' Example: MessageBox.Show(IncrementString("test219")) ' => 220Function IncrementString(ByVal text As String) As String    Dim index As Integer    Dim i As Integer    For i = text.Length - 1 To 0 Step -1        Select Case text.Substring(i, 1)            Case "0" To "9"            Case Else                index = i                Exit For        End Select    Next    If index = text.Length - 1 Then        Return text & "1"    Else        Dim value As Integer = Integer.Parse(text.Substring(index + 1)) + 1        Return text.Substring(0, index) & value.ToString()    End IfEnd Function

See also  Comparing different methods of testing your Infrastructure-as-Code
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist