Regex to find words with specific character

后端 未结 3 1745
别那么骄傲
别那么骄傲 2021-01-29 02:27

How to find all words which contain a specific letter in it?

For example, if my string is

This is a Station called South Yarra

then I

3条回答
  •  被撕碎了的回忆
    2021-01-29 03:02

    Solution without regex using Linq :

    List arr = s.Split(' ').Where(x => x.Contains('a')).ToList();
    

    string.Split(' ') : It return array of strings that contains the substrings in this instance that are delimited by ' '

    Enumerable.Where(predicate) : Filter sequence based on predicate

    Enumerable.Contains() : Determines whether a sequence contains a specified element

    POC: .net Fiddle

提交回复
热议问题