VB中设计算法统计单词的个数和找出最长单词
首先在文本框中读入一篇英语文章。然后编写命令按钮的Click事件,统计和寻找,然后在LABEL上输出结果。
统计单词个数 Dim a As Variant Dim i As Integer, intWordCount As Integer a = Split("I love you") intWordCount = 0 For i = 0 To UBound(a) If a(i) <> "" Then intWordCount = intWordCount + 1 End If Next i MsgBox intWordCount & "个单词" 找最长单词 Function longest(S As String) As String Dim p() As String, n As Integer S = Replace(S, vbCrLf, " ") p = Split(S, " ") For i = 0 To UBound(p) If Len(p(i)) > Len(p(n)) Then n = i Next longest = p(n) End Function 。
答:新建 3个 textbox,在新建 1个Commandbutton,再在Commandbutton中输入 Private Sub Command1_Click(...详情>>
答:详情>>