Function LCS(ByVal A As String, ByVal B As String) As String
If Len(A) * Len(B) = 0 Then LCS = "": Exit Function
Dim la As Integer, lb As Integer, achar() As String, bchar() As String, c() As Integer, i As Integer, j As Integer, max As Integer
la = Len(A)
lb = Len(B)
ReDim achar(la - 1)
ReDim bchar(lb - 1)
ReDim c(la - 1)
For i = 1 To la
achar(i - 1) = Mid(A, i, 1)
Next
For i = 1 To lb
bchar(i - 1) = Mid(B, i, 1)
Next
max = 0
For i = 0 To lb - 1
For j = la - 1 To 0 Step -1
If bchar(i) = achar(j) Then
If i * j = 0 Then
c(j) = 1
Else
c(j) = c(j - 1) + 1
End If
Else
c(j) = 0
End If
If c(j) > max Then max = c(j): LCS = Mid(A, j + 2 - max, max)
Next
Next
If max = 0 Then LCS = ""
End Function
Private Sub Command1_Click()
MsgBox LCS("如果你想推荐本文到CSDN 技术中心,请选择下列的文章分类之一。文章保存时将自动提交到CSDN技术中心,通过审核后本文将出现在您的CSDN 技术中心的专栏中。", "如果您不希望本文被提交到CSDN技术中心,请选择""不发表到CSDN技术中心""")
End Sub
返回 “提交到CSDN技术中心,”