# 取指定定界符中间的内容
def mid(content: str, beginString: str = '', endString: str = ''):
"""
取指定定界符中间的内容
:param content: str 要截取的字符串
:param beginString: str 开始定界符
:param endString: str 结束定界符
:return: str 子串
"""
if len(beginString) > 0:
beginPos = content.find(beginString)
if beginPos == -1:
return ''
else:
beginPos = -1
if len(endString) == 0:
if beginPos == -1:
return ''
return content[beginPos + 1:]
endPos = content.find(endString)
return content[beginPos + 1:endPos]
[原] Python 取指定定界符中间的内容
最新推荐文章于 2023-03-22 13:45:00 发布
本文介绍了一种从给定字符串中通过指定的开始和结束定界符来截取出子串的方法。该方法适用于多种应用场景,如数据解析、配置文件读取等。


1030

被折叠的 条评论
为什么被折叠?



