在另一个字符串中找到一个字符串

时间:2018-11-14 02:46:44

标签: python-3.x

我正在尝试编写一个函数以在消息中查找字符串,但是在设置索引时遇到了麻烦。我希望我的函数查找给定消息中所有出现的字符串并打印。非常感谢您的帮助。谢谢!

代码:

def find_substr(mssg, search):


    searchstr = str(search)
    mssgstr = str(mssg)
    ix = 0

    a = []
    found = False
    while ix < len(mssgstr):     # Condition to loop
        if searchstr == mssgstr[]:
            a.append(c)
            found = True
        ix = ix + 1

    if found and c == len(mssgstr):


        for i in a:
            print(i)
    else:
        print(-1)
messag = " man man women women man"

find_substr(messag, "man")

0 个答案:

没有答案
相关问题