vbs-求两个字符的公共字符串
上一篇 /
下一篇 2010-09-13 11:58:36
/ 个人分类:我的自动化学习
Option Explicit
Function findPublicStr ( str1 , str2 )
Dim shortStr, longStr
Dim maxlength
If len(str1) > len(str2)Then
maxlength = len(str2)
shortStr = str2
longStr = str1
else
maxlength = len(str1)
longStr = str2
shortStr = str1
End If
Dim i, j
Dim str , pubstr, temp, result
temp = 0
For i = 1 to maxlength step 1
For j = maxlength to 1 step -1
str =mid (shortStr, i, j)
If instr(longStr, str) >0 Then
pubstr = str
If len(pubstr) > temp Then
result = pubstr
temp = len(pubstr)
End If
End If
Next
Next
findPublicStr = result
End Function
msgbox findPublicStr( "2341234", "245412")
收藏
举报
TAG: