查找子字符串是否包含在字符串中

问题描述

我想知道是否有一种直接的方法可以知道给定的子字符串是否存在于一个字符串中严格 中间(即)不是开始而不是结束,但是字符串中包含的某处。

substring = "trees"

input1 = "sketchthetreesanddaffodils"
input2 = "treesaregreen"
input3 = "greentrees"
input4 = "greentreesareoftengreenertrees"

output1 = True 
output2 = False # 'trees' appearing at the beginning though
output3 = False # 'trees' appearing at the end though
output4 = True  # 'trees' appear in middle,regardless of the one in the end 

预期操作

str.containsinmiddle()
#Something similar to str.startswith(),str.endswith()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)