The basic idea of the Brute-Force algorithm is: from the target string s = "s0s1... the first character of the sn-1 starts and the pattern string t = "t0t1t2... the first character comparison in the tn-1, if equal, continues to compare subsequent characters one by one; otherwise recompares from the second character of the target string to the first character of the pattern string t. Similarly, if each character starting with the I character of the mode string s is the same as the corresponding character in the t character of the target string, the match is successful and I is returned. Otherwise, the match fails, the algorithm returns-1.
Int index (SqString s, SqString t) {int I = 0, j = 0; while (I <s. length & j <t. length) {if (s. data [I] = t. data [j]) {I ++; j ++;} else {I = I-j + 1; j = 0 ;}} if (j> = t. length) return (i-t.length); else return-1 ;}