编写程序VB,在一个文本框中输入一个简单的英文句子,找出这个英文句子中最长的单词

1个回答

  • Private Sub Command1_Click()

    If Text1.Text = "" Then Exit Sub

    Dim word As Variant,s As String

    Dim k As Integer,maxw As String,n As Integer

    s = Replace(Replace(Text1.Text,","," "),"."," ")

    s = Replace(Replace(s,","," "),"."," ")

    s = Replace(s,vbCrLf," ")

    s = Trim(Replace(s," "," "))

    If s = "" Then Exit Sub

    word = Split(s," ")

    n = UBound(word)

    For k = 0 To n

    If n = k Then Exit For

    If Len(CStr(word(k + 1))) > Len(maxw) Then

    maxw = word(k + 1)

    End If

    Next

    MsgBox maxw & "=" & Len(maxw) & "字节"

    End Su