用vb求字符串最长单词的函数,谢谢
主程序通过调用该函数求出用户输入的英文语句段中最长的单词及长度。要求:窗体中设置三个文本框,其中一个作为输入英文语句段,另外两个作为输出计算结果。再添加一个命令按钮,用于...
主程序通过调用该函数求出用户输入的英文语句段中最长的单词及长度。要求:窗体中设置三个文本框,其中一个作为输入英文语句段,另外两个作为输出计算结果。再添加一个命令按钮,用于启动程序计算功能。输入完毕后,单击该命令按钮,就会输出结果。
展开
展开全部
Private Sub Command1_Click()
Dim ss As String
ss = LWord(Text1.Text)
Text2.Text = ss
Text3.Text = Len(ss)
End Sub
Private Function LWord(ws As String) As String
Dim s() As String, i As Long, k As String
s = Split(ws, " ")
k = ""
For i = 0 To UBound(s)
If Len(s(i)) > Len(k) Then k = s(i)
Next
LWord = k
End Function
Dim ss As String
ss = LWord(Text1.Text)
Text2.Text = ss
Text3.Text = Len(ss)
End Sub
Private Function LWord(ws As String) As String
Dim s() As String, i As Long, k As String
s = Split(ws, " ")
k = ""
For i = 0 To UBound(s)
If Len(s(i)) > Len(k) Then k = s(i)
Next
LWord = k
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询