实现上述功能的VB程序如下:
Private Sub Command1_Click()
Dim a(1 To 1000) As String '数组a存储文中出现该指定单词(或字符串)的各个位置
Dim s As String, c As String ,ch As String
Dim n As Integer, max As Integer, i As Integer
s = Text1.Text
c = Text2.Text
n = 0: Max = 0
For i = 1 To Len(s) - Len(c) + 1
ch = ①
If ch = c Then
n = n + 1
a(n) = i
If n >= 2 Then
If a(n) - a(n - 1) - Len(c) > Max Then Max = a(n) - a(n - 1) - Len(c)
End If
End If
Next i
Text3.Text = ②
End Sub
以上程序段运行时,为了实现上述功能,划线处①和②应填入的代码分别为:
① ②