How to implement incremental search on a list

前端 未结 7 2087
无人共我
无人共我 2021-02-06 04:52

I want to implement incremental search on a list of strings. Consider I have an array containing which contains the strings store,state,stamp,crawl,crow. My application has a te

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-06 05:01

    Below is a function that will incrementally search a string for a substring to match.

    public IEnumerable FindAllMatches(string toMatch, string source) {
      var last = 0;
      do {
        var cur = source.IndexOf(toMatch,last);
        if ( cur < 0 ) {
          break;
        }
        yield return cur;
        last = cur + toMatch.Length;
      while(true);
    }
    

提交回复
热议问题