View Code
 1         /// <summary>
 2         /// 蛮力法实现字符串匹配
 3         /// </summary>
 4         /// <param name="longStr"></param>
 5         /// <param name="shortStr"></param>
 6         /// <returns></returns>
 7         private static bool IsContains(string longStr, string shortStr)
 8         {
 9             //字符串总长度
10             int longLength = longStr.Length;
11             //匹配字符串的长度
12             int shortLength = shortStr.Length;
13             int j;
14             //是否匹配成功的标志,默认未匹配成功
15             bool isFunded = false;
16             for (int i = 0; i <= longLength-shortLength; i++)
17             {
18                 j = 0;
19                 while (j < shortLength && shortStr[j] == longStr[i + j])
20                 {
21                     j++;
22                 }
23                 if (j == shortLength)
24                 {
25                     isFunded = true;
26                     break;
27                 }
28             }
29             return isFunded;
30         }
posted on 2012-05-11 14:01  捣乃忒  阅读(158)  评论(0)    收藏  举报