Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,857 answers

573 users

How to check if second string is subsequence of first string in VB.NET

1 Answer

0 votes
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
' 

 





answered Mar 24 by avibootz
...