Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: Intermediate
Jun 30, 2003

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

' Increment the numeric right-most portion of a string
' Example: MessageBox.Show(IncrementString("test219")) ' => 220

Function 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 If
End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date