zoukankan      html  css  js  c++  java
  • C# 搜索关键词

    例如有一个字符串“Google Nexus 4 mobile phone”,你要搜索“Google”和“Nexus”,那么应该返回TRUE。

            static void Main(string[] args)
            {
                string[] strArr = { "Nexus","Google"};
                string str = "Google Nexus 4 mobile phone";
                Console.Write(MatchKeyWords(str, strArr));
            }
    
            static bool MatchKeyWords(string str, string[] keyWords)
            {
                for (int i = 0; i < keyWords.Length; i++)
                {
                    if (MatchOneWords(str, keyWords[i]) == false)
                        return false;
                }
    
                return true;
            }
    
            static bool MatchOneWords(string str, string word)
            {
                int i = 0;
                int j = 0;
                while (i<str.Length&&j<=word.Length)
                {
                    if (str[i]== word[j])
                    {
                        i++;
                        j++;
                    }
                    else
                    {
                        i++;
                        j = 0;
                    }
                    if (j == word.Length)
                    {
                        return true;
                    }
                }
    
                return false;
            }
    View Code
  • 相关阅读:
    手势识别 ios
    无题
    核心动画笔记
    Quartz2D的学习2
    Quartz2D的学习1
    NSURLsessionTask
    NSURLSession
    POST请求的两种方式
    网络第一天
    NSThread
  • 原文地址:https://www.cnblogs.com/Ligeance/p/3147552.html
Copyright © 2011-2022 走看看