本文介绍了字符串操作在文本框中对单词进行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我对一个句子中的元音进行计数的方法,如何得到它来对句子中的单词数进行计数?获得总字数后,我需要一个消息框来显示字数,然后反转句子并将其倒退到文本框中.
Below is what I have for counting vowels in a sentence how do I get it to count the number of words in the sentence? After I get the total word count I need a message box to show the count then reverse the sentence and put it in backwards into the text box.
<pre lang="vb">Public Function CountVowels(ByVal strSentence As String, ByRef intVowels As Integer) As Integer<br />
Dim intIndex As Integer<br />
Dim strCurrentLetter As String<br />
strSentence.ToLower()<br />
<br />
For intIndex = 0 To strSentence.Length - 1<br />
strCurrentLetter = strSentence.Substring(intIndex, 1)<br />
If strCurrentLetter = "a" Or strCurrentLetter = "e" Or strCurrentLetter = "i" Or strCurrentLetter = "o" Or strCurrentLetter = "u" Then<br />
intVowels += 1<br />
End If<br />
Next<br />
Return intVowels<br />
End Function</pre><br />
推荐答案
Dim text As String = "the quick, brown fox,jumps over the lazy dog"
Dim words As String() = text.Split(New Char() {" "C, ","C, "."C, "?"C, "!"C}, StringSplitOptions.RemoveEmptyEntries)
Dim i As Integer = words.Length
然后,您可以将其作为句子向后重建,并将其显示在MessageBox中.我不会给您该代码:您应该做一些自己的作业! :laugh:
[edit]添加了重建注释-OriginalGriff [/edit]
You can then rebuild the parts backwards as a sentence and display that in a MessageBox. I won''t give you that code: You should do some of your own homework! :laugh:
[edit]Added rebuild comment - OriginalGriff[/edit]
这篇关于字符串操作在文本框中对单词进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!