vb编一子过程maxlength(s,maxword),在已知的字符串s中,找出最长的单词maxword,字符串内用空格分隔单词。
1个回答
展开全部
Private Sub maxlength(s, maxword)
Dim temp, wmax, nmax
temp = Split(s, " ")
wmax = 0
For i = LBound(temp) To UBound(temp)
If Len(temp(i)) > wmax Then
wmax = Len(temp(i))
nmax = i
End If
Next
maxword = temp(nmax)
End Sub
Private Sub Form_Click()
Dim astr As String
astr = Text1.Text 'Text1输入字符串s
maxlength astr, maxword
Text2.Text = maxword 'text2显示最长的单词
End Sub
Dim temp, wmax, nmax
temp = Split(s, " ")
wmax = 0
For i = LBound(temp) To UBound(temp)
If Len(temp(i)) > wmax Then
wmax = Len(temp(i))
nmax = i
End If
Next
maxword = temp(nmax)
End Sub
Private Sub Form_Click()
Dim astr As String
astr = Text1.Text 'Text1输入字符串s
maxlength astr, maxword
Text2.Text = maxword 'text2显示最长的单词
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询