介绍
该函数可以在给定的字符串str1和str2里找出并返回长度最大的公共子串。详细信息在源码里有说明。源码如下:
def getMaxLenSameSubStr(str1, str2, isLower=False):
# 说明
# 该函数是在给定的两个字符串str1和str2中找出长度最长的相同的子串
# str1和str2分别为给定的两个字符串
# isLower标记是否区分大小写,False不区分,True区分,默认为False
# 返回结果为字典格式:{maxLen: [maxSub1, maxSub2, maxSub3, ...]}
# 没有公共子串的结果为:{0: []}
# 如果传参不是字符串类型,强制转换,并将短字符串赋值给str1
str1 = str(str1)
str2 = str(str2)
if not str1 or not str2:
return {
0:[]}
if len(str1) > len(str2):
str1, str2 = str2, str1
# 是否区分大小写
if isLower:
str1, str2 = str1.lower()