Check if a string is substring of another | Python program for the above approach ; Iterate from 0 to Len - 1 ; Driver code
def Substr ( Str , target ) : NEW_LINE INDENT t = 0 NEW_LINE Len = len ( Str ) NEW_LINE i = 0 NEW_LINE for i in range ( Len ) : NEW_LINE INDENT if ( t == len ( target ) ) : NEW_LINE INDENT break NEW_LINE DEDENT if ( Str [ i ] == target [ t ] ) : NEW_LINE INDENT t += 1 NEW_LINE DEDENT else : NEW_LINE INDENT t = 0 NEW_LINE DEDENT DEDENT if ( t < len ( target ) ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT return ( i - t ) NEW_LINE DEDENT DEDENT print ( Substr ( " GeeksForGeeks " , " Fr " ) ) NEW_LINE print ( Substr ( " GeeksForGeeks " , " For " ) ) NEW_LINE