2024-10-01 07:27:55 发布
网友
我在Python中寻找一个函数,用于检查字符串a是否包含在字符串B中,以及两个字符串的上/下字符的任意组合。你知道吗
示例:
a = 'uaUa' b = 'this is a longer string containing uaua'
checkString (a, b)返回True,因为a包含在b中
checkString (a, b)
True
试试https://docs.python.org/2/library/re.html#re.search
>>> import re >>> a = 'uaUa' >>> b = 'this is a longer string containing uaua' >>> print bool( re.search(a, b, re.IGNORECASE) ) True
您可以使用“.lower()”方法将两个字符串转换为小写(例如),然后使用Python字符串功能的标准find方法。你知道吗
def checkString(a, b): return a.lower() in b.lower()
试试https://docs.python.org/2/library/re.html#re.search
您可以使用“.lower()”方法将两个字符串转换为小写(例如),然后使用Python字符串功能的标准find方法。你知道吗
相关问题 更多 >
编程相关推荐