' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.Text

Class MainClass
    Public Shared Function makeids(ByVal tbl As String) As String
        Dim sb As StringBuilder = New StringBuilder 
        Dim oldix As Integer = 0
        Dim ix As Integer = 0
        Dim n As Integer = 0
        ix = tbl.IndexOf("<td>", oldix)
        While ix >= 0
            n = n + 1
            sb.Append(tbl.Substring(oldix, ix - oldix))
            sb.Append("<td id='" & n & "'>")
            oldix = ix + "<td>".Length
            ix = tbl.IndexOf("<td>", oldix)
        End While
        sb.Append(tbl.Substring(oldix))
        Return sb.ToString
    End Function
    Public Shared Sub Main(ByVal args As String())
        Console.WriteLine(makeids("<td>aaa</td>"))
        Console.WriteLine(makeids("aaa<td>bbb</td>ccc<td>ddd</td>eee"))
        Console.WriteLine(makeids("<td>aaa</td><td>bbb</td>"))
        Console.WriteLine(makeids("aaa"))
        Console.WriteLine(makeids(""))
    End Sub
End Class 
