text: Check if a string can be repeated to make another string | C # implementation of the approach ; Function to return the count of repetitions of string a to generate string b ; If b cannot be generated by repeating a ; Repeat a count number of times ; Driver code
code: using System ; class GfG { static int getCount ( String a , String b ) { if ( b . Length % a . Length != 0 ) return - 1 ; int count = b . Length / a . Length ; String str = " " ; for ( int i = 0 ; i < count ; i ++ ) { str = str + a ; } if ( str . Equals ( b ) ) return count ; return - 1 ; } public static void Main ( String [ ] args ) { String a = " geeks " ; String b = " geeksgeeks " ; Console . WriteLine ( getCount ( a , b ) ) ; } }