c# - 在字符串数组中打印出特定字符出现次数最多的字符串

标签 c# arrays string loops

我需要从一个字符串数组中打印出字符串,该数组中特定字符的出现次数最多。

例子:

{"I","have","feelings"} , 'e' 打印“feelings”。

{"doodlidoo","foo","moon"} , 'o' 打印“doodlidoo”。

到目前为止,我已经想出了这个,它可以找到每个字符串的长度。我只需要弄清楚如何打印单个字符串。

 public static String MostLettersInWord(String[] list, char c)
 {
    for (int x = 0; x < list.Length; x++)
     {
      int count = list[x].Split(c).Length - 1;
     }
     return list[0];
 }

最佳答案

试试这个:-

var word = words.OrderByDescending(x => x.Count(z => z == c)).First();

Working Fiddle .

关于c# - 在字符串数组中打印出特定字符出现次数最多的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27876571/

相关文章:

c# - 用现代 OO C 类语言执行此操作的好方法吗?

c++ - 列表功能 C++

用户输入数组后出现 C++ 运行时错误

c - 读取一个字符串,当找到换行符时将每个字符串存储到数组中

c# - C# 中的 CRLF 解析布鲁斯

C# 7 使用模式匹配不起作用

c# - 裁剪位图并根据需要扩大尺寸

c# - 如何在 ModelView 中防止 WPF 枚举

C++ 指针数组

python - 在 python3 中写入 csv 中的 io.BytesIO 失败