Check if a string can be split into two substrings such that one substring is a substring of the other | C # program to implement the above approach ; Function to check if a string can be divided into two substrings such that one substring is substring of the other ; Store the last character of S ; Traverse the characters at indices [ 0 , N - 2 ] ; Check if the current character is equal to the last character ; If true , set f = 1 ; Break out of the loop ; Driver code ; Given string , S ; Store the size of S ; Function Call
using System ; class GFG { static void splitString ( string S , int N ) { char c = S [ N - 1 ] ; int f = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( S [ i ] == c ) { f = 1 ; break ; } } if ( f != 0 ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } public static void Main ( ) { string S = " abcdab " ; int N = S . Length ; splitString ( S , N ) ; } }