需要在字符串中显示每个单词的平均字母并显示
这是我到目前为止所拥有的,它设置为显示我需要保留或修改以保留的单词总数,以允许显示每个单词中的平均字母数量,如果可以的话,请帮助任何人。非常
!
{
string words = tbxArgument.Text.Trim();
MessageBox.Show("Number of Words: " + CountWords(words));
}
感谢
{
string[] allWords = words.Split(' ');
return allWords.Length;
}
Here is what I have so far, it is set up to display the total number of words, which I need to keep, or modify to keep to allow the average number of letters in each word to be displayed, please assist anyone if you can. thank you so much!:
private void btnCheck_Click(object sender, EvenArgs e)
{
string words = tbxArgument.Text.Trim();
MessageBox.Show("Number of Words: " + CountWords(words));
}
private int CountWords(string words)
{
string[] allWords = words.Split(' ');
return allWords.Length;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定这是否是您要完成的工作。
但这将为您提供所有单词的平均长度。
Not sure If this is what you are trying to accomplish.
But this will give you the average length of all the words.
这是一种仅在字符串上结合的方法,而无需分配需要额外的内存。只是一种优化,用于娱乐:
我简单地迭代检查空白和空白之间的更改(数量算词),然后在阅读字母时,计数字母。最后,如果我们正在阅读字母,而《最后的字符》是一封信,则必须添加最后一句话才能计数。
This is a method that only interate over the string, without making splits that require allocate extra memory. Just an optimization, for entertainment:
I simply iterate checking the changes between blank and not blank (to count words) and, while reading letters, counting letters. At the end, if we are reading letters and last char is a letter, we must add the last word to count.