如何计算单词数量 [英] How to calculate the number of words

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

问题描述

我想写一个程序来计算特定文本字符串中特定单词的单词数

I want to write a program that calculates the number of words in a particular word in a particular text string

推荐答案

计数单词包括空格

Count words include space
dim count_ as double = textbox1.text.lenght 

Or

dim count_ as double = len(textbox1.text)


不确定你的意思,特定单词中的单词数。



如果你的意思是你想要计算字符串中的单词,那么这里是你的起点(检查确切的语法)。它假定每个单词之间有一个空格。



Not sure what you mean by, "the number of words in a particular word".

If you mean you want to count words in a string then here''s a starting point for you (check the exact syntax). It assumes a single space between each word.

dim words as string() = sentence.split(" ")
dim wordCount as integer = words.length





查看string.replace()方法以获取一种简单的删除方法来自输入的多个空格。然后看一下正则表达式,找出一种更复杂的方法来删除多次出现的字符/字符串。



如果这不是你的问题的意思请举一个例子你要做什么。



Look at the string.replace() method for a simple way of removing multiple spaces from the input. Then look at regex for a more sophisticated way of removing multiple occurrences of characters/strings.

If that isn''t what you mean by your question please give an example of what you''re trying to do.


这篇关于如何计算单词数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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