Hat man eine Nummer und möchte dynamisch eine Folgenummer bilden, die sich nach dem letzten Zeichen richtet, kann man in Visual Basic folgende Funktion verwenden:
Imports System.Text.RegularExpressions Module VBModule Function NextLetter(c As String) As String If c = "Z" Then Return "Z-1" ElseIf c = "z" Then Return "z-1" End If Return Chr(Asc(c) + 1) End Function Function NextNr(ByVal val As String) As String Dim regPatternNumber As String = "\d+$" Dim regNumber As Regex = New Regex(regPatternNumber) Dim matchNumber As Match = regNumber.Match(val) Dim regPatternChar As String = "[A-Za-z]+$" Dim regChar As Regex = new Regex(regPatternChar) Dim matchChar As Match = regChar.Match(val) If matchNumber.Success Then Dim NextNumber As Integer = Convert.toInt32(matchNumber.value) NextNumber = NextNumber + 1 Return Regex.Replace(val, regPatternNumber, cstr(NextNumber)) ElseIf matchChar.Success Then Return Regex.Replace(val, regPatternChar, NextLetter(matchChar.value)) Else Return val + "-1" End If Return "_" End Function Sub Main() Console.WriteLine(NextNr("A/1")) Console.WriteLine(NextNr("A/1/B")) Console.WriteLine(NextNr("A/1/Z")) Console.WriteLine(NextNr("A/1/[")) Console.WriteLine(NextNr("A/1/10")) End Sub End Module
Die gleiche Funktion in PHP findet man hier.