Maximum number of occurrences a character appears in an array of strings

前端 未结 3 521
刺人心
刺人心 2021-01-20 01:31

In C#, given the array :

string[] myStrings = new string[] {
  \"test#test\",
  \"##test\",
  \"######\", // Winner (outputs 6)
};

How can

3条回答
  •  悲&欢浪女
    2021-01-20 02:25

    You can do that with Linq combined to Regex:

    myStrings.Select(x => Regex.Matches(x, "#").Count).max();
    

提交回复
热议问题