查找给定单词的频率 [英] find frequency of the given words

查看:80
本文介绍了查找给定单词的频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何找到给定单词的频率c#.net

pls tell me how to find frequency of the given words c#.net

推荐答案

这看起来像是一项作业,我们通常不做作业对于这里的人.但是,在我想出答案之前,那想法的手并没有出现在我身上,所以请以为自己很幸运,您完全得到了答复.
FWIW,您应该找到另一个小问题,因为他没有教您可以说是最重要的程序员技能-分析.

-------------

将字符串拆分为单词集合,然后使用LINQ计数给定单词的实例数.

This looks like a homework assignment, and we don''t generally do homework for people here. However, that thought hand''t occurred to me before I came up with the answer, so consider yourself lucky thata you got a response at all.
FWIW, you should find another isntructor because he''s not teaching you the arguably most important programmer skill - analysis.

-------------

Split the string into an collection of words, and then use LINQ to count the number of instances of a given word.

string mywordString = "around the rugged rock the ragged rascal ran";
string findWord = "the";

// at this point, you probably want to remove everything that''s not a 
// space or alhanumeric character. You can probably come up eith a 
// regex object for that.

List<string> words = new List<string>();
words.Add(words.ToLower().Split(" "));
findWord = findWord.ToLower();

int count = (from word in words 
             where word == findWord 
             select word).Count();



您可能需要稍作调整,但是它提供了如何解决问题的要点.



You may have to tweak it a little, but it provides the gist of how you could approach the problem.


这篇关于查找给定单词的频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆