Imports System
Public Class Program
Public Shared Function isSecondStringSubsequenceOfFirstString(ByVal first As String, ByVal second As String) As Boolean
Dim i As Integer = 0, j As Integer = 0
While i < first.Length
If j >= second.Length Then
Return False
End If
If first(i) = second(j) Then
Console.Write("first(i) = " & first(i) & " second(j) = " & second(j))
Console.WriteLine(" i = " & i & " j = " & j)
i += 1
End If
j += 1
End While
Return True
End Function
Public Shared Sub Main(ByVal args As String())
Dim first As String = "vb programming"
Dim second As String = "vb.net programming"
Console.WriteLine(If(isSecondStringSubsequenceOfFirstString(first, second), "yes", "no"))
End Sub
End Class
' run:
'
' first(i) = v second(j) = v i = 0 j = 0
' first(i) = b second(j) = b i = 1 j = 1
' first(i) = second(j) = i = 2 j = 6
' first(i) = p second(j) = p i = 3 j = 7
' first(i) = r second(j) = r i = 4 j = 8
' first(i) = o second(j) = o i = 5 j = 9
' first(i) = g second(j) = g i = 6 j = 10
' first(i) = r second(j) = r i = 7 j = 11
' first(i) = a second(j) = a i = 8 j = 12
' first(i) = m second(j) = m i = 9 j = 13
' first(i) = m second(j) = m i = 10 j = 14
' first(i) = i second(j) = i i = 11 j = 15
' first(i) = n second(j) = n i = 12 j = 16
' first(i) = g second(j) = g i = 13 j = 17
' yes
'