How to check if a string is rotation of another string in C#

1 Answer

0 votes
using System;
 
class Program
{
    static bool isRotation(String s1, String s2) { 
        return (s1.Length == s2.Length) &&  
               ((s1 + s1).Contains(s2)); 
    } 
 
    static void Main() {
        String s1 = "abbc"; 
        String s2 = "cabb"; 
 
        Console.WriteLine(isRotation(s1, s2) ? "yes" : "no");
       
        s1 = "abbc"; 
        s2 = "bbac"; 
 
        Console.WriteLine(isRotation(s1, s2) ? "yes" : "no");
    }
}
 
 
 
/*
run:
 
yes
no
 
*/

 



answered Sep 26, 2019 by avibootz
edited Sep 26, 2019 by avibootz

Related questions

1 answer 110 views
1 answer 104 views
1 answer 178 views
1 answer 132 views
1 answer 180 views
1 answer 145 views
...