How to find the first occurrence of a pattern in a string from some starting position in VB.NET

1 Answer

0 votes
Imports System

Class Program
    Public Shared Sub Main()
        Dim str As String = "abcdefgaaahijklaaaamnopqaaaaarst"
        Dim pattern As String = "aaa"
        Dim startPosition As Integer = 11
        Dim foundPosition As Integer = str.IndexOf(pattern, startPosition)

        If foundPosition <> -1 Then
            Console.WriteLine($"Pattern found at position: {foundPosition}")
        Else
            Console.WriteLine("Pattern not found!")
        End If
    End Sub
End Class


 
' run:
'
' Pattern found at position: 15
'

 



answered Jun 10 by avibootz
...