python根据开头和结尾字符串获得指定字符串的中间字符串的代码

2019-02-08  本文已影响0人  程序媛宝

在学习闲暇时间,将写内容过程比较常用的内容片段做个记录,下面内容是关于python根据开头和结尾字符串获得指定字符串的中间字符串的内容,应该能对小伙伴也有用途。

def GetMiddleStr(content,startStr,endStr):

    startIndex = content.index(startStr)

    if startIndex>=0:

        startIndex += len(startStr)

    endIndex = content.index(endStr)

    return content[startIndex:endIndex]

if __name__=='__main__':

返回结果

上一篇 下一篇

猜你喜欢

热点阅读