zoukankan      html  css  js  c++  java
  • 统计一个子字符在另外一个字符串中出现的次数

    #coding = utf-8
    '''
    Created on 2015年5月30日 
    author: likui
    '''
    
    def findstr(desStr,subStr):
        '该函数统计一个子字符在另外一个字符串中出现的次数'
        des_len=len(desStr)
        sub_len=len(subStr)
        des2list=list(desStr)
        temp=[]
        
        if subStr not in desStr:
            print('关键字不存在')
        else:
            for each1 in range(des_len):
                des_temp=des2list[each1:each1+sub_len]
                temp_str=''
                for each2 in des_temp:
                    temp_str+=each2
                temp.append(temp_str)
        count=temp.count(subStr)
        print('字符出现了%d次'%count)
        
    findstr('你的世界你做主你的世你做主你的界你做主你的界你做主', '你的世界')


  • 相关阅读:
    studyframe项目总结
    js三级联动
    ajax提交,获取后台数据
    密码验证
    产生验证码
    使用泛型 ,做计算器
    web前端,css
    VS快捷键
    我的未来编码规范
    如何将CAJ文档转化为doc文档
  • 原文地址:https://www.cnblogs.com/lkpp/p/7400056.html
Copyright © 2011-2022 走看看