开发者

Simple string match

开发者 https://www.devze.com 2023-03-05 09:55 出处:网络
I want to do a simple string match, searching from the -front- of the string.Are there easier ways to do this with maybe a builtin? (re seems like overkill)

I want to do a simple string match, searching from the -front- of the string. Are there easier ways to do this with maybe a builtin? (re seems like overkill)

de开发者_运维百科f matchStr(ipadr = '10.20.30.40', matchIP = '10.20.'):
    if ipadr[0:len(matchIP)] == matchIP: return True
    return False


def matchStr(ipadr = '10.20.30.40', matchIP = '10.20.'):
    return ipadr.startswith(matchIP)


>>> 'abcde'.startswith('abc')
True


'10.20.30.40'.startswith('10.20.')
>>>True
0

精彩评论

暂无评论...
验证码 换一张
取 消