vb中输入一行英文句子(单词之间有一个空格,最后用句号结束)找出其中最长的单词,输入该单词和它的长度。
输入一行英文句子(单词之间有一个空格,最后用句号结束)找出其中最长的单词,输入该单词和它的长度。要求编写Function过程中用于找到最长的单词,在事件过程中输入英文句子...
输入一行英文句子(单词之间有一个空格,最后用句号结束)找出其中最长的单词,输入该单词和它的长度。要求编写Function过程中用于找到最长的单词,在事件过程中输入英文句子并输出结果。
要代码 展开
要代码 展开
3个回答
展开全部
Private Sub Command1_Click()
Dim Word() As String, LongestWord As String, LongestWordLength As Integer
Word = Split(Left(Text1.Text, Len(Text1.Text) - 1), " ")
LongestWordLength = 0
For i = LBound(Word) To UBound(Word)
If Len(Word(i)) > LongestWordLength Then
LongestWord = Word(i)
LongestWordLength = Len(Word(i))
End If
Next i
Label1.Caption = "最长的单词为“" + LongestWord + "”,其长度为" + CStr(LongestWordLength) + "。"
End Sub
2017-05-18
展开全部
其实这个很简单吧,就是查找每个空格之间的长度,把最长的那个显示出来而已。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim t As String, t1 As String, t2 As String * 1
Dim i As Integer, j As Integer, l As Integer, ascii As Integer, m As Integer, k As Integer
t = InputBox("Please input a sentence ,end of .")
l = Len(t)
ReDim a(l) As String
ReDim n(l) As Integer
j = 1
For i = 1 To l
t1 = Mid(t, i, 1)
If t1 = "" Then t1 = " "
ascii = asc(t1)
If (ascii > 65 And ascii < 90) Or (ascii > 97 And ascii < 122) Then
a(j) = a(j) + t1
n(j) = n(j) + 1
Else
If n(j) > n(j - 1) Then m = n(j): k = j
j = j + 1
End If
Next
Print "The longest word is:" & a(k) & ", long is: " & m
End Sub
Dim t As String, t1 As String, t2 As String * 1
Dim i As Integer, j As Integer, l As Integer, ascii As Integer, m As Integer, k As Integer
t = InputBox("Please input a sentence ,end of .")
l = Len(t)
ReDim a(l) As String
ReDim n(l) As Integer
j = 1
For i = 1 To l
t1 = Mid(t, i, 1)
If t1 = "" Then t1 = " "
ascii = asc(t1)
If (ascii > 65 And ascii < 90) Or (ascii > 97 And ascii < 122) Then
a(j) = a(j) + t1
n(j) = n(j) + 1
Else
If n(j) > n(j - 1) Then m = n(j): k = j
j = j + 1
End If
Next
Print "The longest word is:" & a(k) & ", long is: " & m
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询