How to search a Substring in String array in C#

前端 未结 4 655
予麋鹿
予麋鹿 2021-01-13 09:55

How to search for a Substring in String array? I need to search for a Substring in the string array. The string can be located in any part of the array (element) or within

4条回答
  •  孤城傲影
    2021-01-13 10:22

    If all you need is a bool true/false answer as to whether the lineVar exists in any of the strings in the array, use this:

     arrayStrings.Any(s => s.Contains(lineVar));
    

    If you need an index, that's a bit trickier, as it can occur in multiple items of the array. If you aren't looking for a bool, can you explain what you need?

提交回复
热议问题