The basic principle of pattern matching in the process of editing a text program, you often need to find all the occurrences of a certain pattern in the text. Typically, a piece of text being edited forms a file, the pattern to be searched is the specific keyword that the user is entering. The algorithm that effectively solves this problem is called the string matching pattern. Formal Description assume that the text is an array of N [1 .... n], while the pattern is an array of M [1... m], where M <n, further assuming that the P and T elements are from a finite letter set, so if 0 "S" N-M and T [S + 1... S + M] = P [1... m] So the pattern P appears in text t, and the offset is spackage jxau. bluedot. lyx;/*** @ liyixiang * @ 2014-8-16 * @ todo: * SIMPLE algorithm for pattern matching */public class bruteforce {/*** @ param1: substring * Main string t length is N * @ param2: childstring * sub-string P length is M * @ return * return offset S * // ***** 1. the first character of the string is compared with the first character of the Main string. If the first character of the string does not match the second character of the Main string, the second character of the Main string is compared * 2. if the first character of the string and If the string matches at a position, the second character of the string is compared with the next position of the main * string, and so on. If they are not equal, repeat the first step. */Public int stringmatching (string substr, string childstr) {int Index =-1; // If yes, the return offset is returned. If no value is returned, the return value is-1 Boolean match = true; // The offset from 0 to the maximum, that is, the length of the Main string. N-the length of the sub-string. mfor (INT I = 0; I <substr. length ()-childstr. length (); I ++) {match = true; For (Int J = 0; j <childstr. length (); j ++) {// if no matching result is found, if (substr. charat (I + J )! = Childstr. charat (j) {match = false ;}// if (MATCH) {Index = I; break ;}} Return Index ;}}