How to check if a string is rotation of another string in VB.NET

1 Answer

0 votes
Imports System

Public Class Test
    Public Shared Function isRotation(s1 As String, s2 As String) As Boolean 
        return (s1.Length = s2.Length) AND 
               ((s1 + s1).Contains(s2))
    End Function
    Public Shared Sub Main()
        Dim s1 As String = "abbc"
        Dim s2 As String = "cabb" 

        Console.WriteLine(if(isRotation(s1, s2),  "yes", "no"))

        s1 = "abbc" 
        s2 = "bbac"

        Console.WriteLine(if(isRotation(s1, s2),  "yes", "no"))
    End Sub
End Class



' run:
' 
' yes
' no
'

 



answered Sep 26, 2019 by avibootz

Related questions

1 answer 106 views
1 answer 100 views
1 answer 170 views
1 answer 128 views
1 answer 170 views
1 answer 141 views
...