计算字符串中单词数量的方法
我只需要一个函数来计算字符串中给定单词的数量。 有一些与分裂有关的事情,但我不知道从那时起我应该做什么。 谢谢你的时间。
PS我忘了提。我很抱歉。我想用 JavaScript 来做到这一点。
I just need a function for counting a given word in a string.
There is something that has to do with split but I cant get what I should do from then.
Thank u for your time.
PS I forgot to mention. My apologies. I want to do that with javascript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为我不知道你想用哪种编程语言来做到这一点。
这是在 Javascript 中根据出现频率进行字数统计的一个很好的示例。
您可以通过单击“尝试此示例”按钮来查看它的作用。
有字数统计、替换和大写功能。您只需要 wordCount() 函数。
As I don't know in which programming language you want to do this.
Here is a nice example of Word counting with frequency of occurrence in Javascript.
You can take a look what its doing by clicking 'Try this example' button.
There is word count, replace and capitalize.You just need the wordCount() function.
按字拆分后,只需将结果数组的长度减一即可。
你用什么编程语言来做这个?
After splitting by the word, just take the length of the resulting array and subtract one.
What programming language are you doing this in?