Checking if ' base ' is base String of ' s2'
for ( int j = 0 ; j < s2 . Length ; ++ j ) { if ( Base [ j % Base . Length ] != s2 [ j ] ) { return false ; } } return true ; } static int countCommonBases ( String s1 , String s2 ) { int n1 = s1 . Length , n2 = s2 . Length ; int count = 0 ; for ( int i = 1 ; i <= Math . Min ( n1 , n2 ) ; i ++ ) { String Base = s1 . Substring ( 0 , i ) ; if ( isCommonBase ( Base , s1 , s2 ) ) { count ++ ; } } return count ; }