Implemented with Java code!
public class Matching {public static void main (string[] args) {BF ();} public static void BF () {String bf_s = "Aaaabbbaab";//main string string bf_t = "Aaab";//pattern string int bfslength = Bf_s.length ();//main string length int Bftlength = Bf_t.length ();//pattern string length for (int i = 0; i < bfslength;) {for (int j = 0; J < Bftlength;) {if (Bf_s.charat (i) = = Bf_t.charat (j)) {//Cycle compares the main string to the pattern string for equality System.out.println (Bf_s.charat (i) + "= =" + Bf_t.charat (j) + ""); /* If the main string matches the pattern string and is the last character of the pattern string, the match succeeds */if (Bf_s.charat (i) = = Bf_t.charat (j) && Bf_t.charat (j) = = Bf_t.charat ( BFTLength-1) {System.out.println ("Match succeeded! "); return;} i++;j++;} else if (Bf_s.charat (i)! = Bf_t.charat (j)) {int count = i + 1; System.out.println ("n" + Count + "time of comparison"); System.out.println (Bf_s.charat (i) + "! =" + Bf_t.charat (j)); i = i-j + 1;//Emphasis, if unequal, the main string moves from the beginning of the previous comparison to the next position compared to the starting position of the pattern string j = 0 (///pattern string starting from the starting position}}}}}
Operation Result:
String Matching--BF algorithm