How to check if strings are rotations of each other in C#

1 Answer

0 votes
using System;

class Program
{
    static bool rotations(String str1, String str2) {
        if (str1.Length != str2.Length)
            return false;

        Console.WriteLine(str1 + str1);
        
        return (str1 + str1).IndexOf(str2) != -1;
    }
    static void Main() {
        String str1 = "abcxd", str2 = "cxdab";
 
        if (rotations(str1, str2))
            Console.Write("yes");
        else
            Console.Write("no");
    }
}







/*
run:
  
abcxdabcxd
yes

*/

 



answered Dec 23, 2021 by avibootz

Related questions

1 answer 176 views
1 answer 124 views
1 answer 191 views
1 answer 160 views
1 answer 165 views
...