E
E
eliasum2020-06-03 19:40:10
C++ / C#
eliasum, 2020-06-03 19:40:10

How to find the most frequently used word in a text?

Hello! How to find the most frequently used word in a text in C#? What approaches can be taken to solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2020-06-03
@eliasum

var text = "test the text test on test platform";
var words = text.Split(' ');
var stat = words.Distinct().ToDictionary(word => word, word => words.Count(x => x == word));
foreach (var (key, value) in stat) Debug.WriteLine($"Word: {key} count: {value}");

D
Developer, 2020-06-03
@samodum

Count the occurrence of words and take among them the one that occurs most often.
A typical task for a student or interview to determine the ability of a candidate to program

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question