ITPub博客

首页 > 应用开发 > IT综合 > Python 查找字符串方法2

Python 查找字符串方法2

原创 IT综合 作者:wzgchen 时间:2016-10-24 11:02:24 0 删除 编辑

#!/bin/env python
#-*- coding:utf-8 -*-


# multiple searches of a string for a substring
# using s.find(sub[ ,start[, end]])
text = "create table t11 (id int,name varchar(20),age int,status varchar(10),sary int unsigned)"
search = 'int'
start = 0
while  True:
    index = text.find(search, start)
    # if search string not found, find() returns -1
    # search is complete, break out of the while loop
    if index == -1:
        break
    print( "%s found at index %d"  % (search, index) )
    # move to next possible start position
    start = index  + 1

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/91975/viewspace-2126984/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-05-01

  • 博文量
    383
  • 访问量
    213569