字符串函数
2015-09-20 17:54
369 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/coodone/article/details/48598627
应用三、
一、chr函数 & ord函数
#输出a01-z26的字样 x = ord("a") print(x) #输出97 i = 0 while i < 26: s = chr(x) if len(str(i +1)) == 2: print(s + str(i + 1)) else: print(s + "0" +str(i + 1)) i += 1 x += 1
二、字符串的应用&匹配
应用一#字符串匹配 sub = "jeap" s = "jeahello jeapedu.com" i = 0 while i <= len(s) - len(sub): j = 0 c = 0 while j < len(sub): if s[i + j] == sub[j]: c += 1 j += 1 if c == len(sub): print(s[i],s[i+1],s[i+2],s[i+3]) #输出jeap i += 1应用二
#je后面和du前面的字符 s = "hello jeapleoowedu.com" head = "je" tail = "du" i = 0 pt = 0 while i <= len(s) - len(head): #why <= j = 0 ch = 0 while j < len(head): #why < if s[i + j] ==head[j]: ch += 1 j += 1 ct = 0 j = 0 while j < len(tail): if s[i +j] == tail[j]: ct += 1 j += 1 if ch == len(head): ph = i if ct == len(tail): pt =i i += 1 #print(ph,pt) sub = "" k = ph + len(head) while k < pt: sub += s[k] k += 1 print(sub)
应用三、
head = "http" tail = ".com" s = "welcome to visit my websit http://www.baidu.com a.com c.com hehe http://163.com or http://www.sohu.com" ph = 0 pt = 0 i = 0 preh = 0 while i <= len(s) - len(head): j = 0 c =0 while j < len(head): if s[i + j] == head[j]: c += 1 j += 1 if c == len(head): ph = i print("ph = ",ph) j = 0 c = 0 while j < len(tail): if s[i + j] == tail[j]: c += 1 j += 1 if c == len(tail): pt = i print("pt = ",pt) if ph < pt and preh != ph: k = ph dns = "" while k < pt + len(tail): dns += s[k] k += 1 print(dns) preh = ph i += 1 ''' 输出结果: pt = 43 http://www.baidu.com pt = 49 pt = 55 ph = 65 pt = 75 http://163.com ph = 83 pt = 98 http://www.sohu.com '''
相关文章推荐
- 字符串函数(二)
- 使用字符串函数输出整数化的PHP版本号
- 字符串函数
- asp之字符串函数示例
- 字符串函数
- C语言字符串函数汇总
- 常用字符串函数
- C语言字符串函数
- 字符串函数memicmp
- 字符串函数strtok
- PHP字符串函数和正则表达式
- Mysql字符串函数收集
- SQL中字符串函数
- Oracle 函数大全(字符串函数,数学函数,日期函数,逻辑运算函数,其他函数)
- WinAPI 字符及字符串函数(10): lstrcpy - 复制字符串
- Oracle 函数大全(字符串函数,数学函数,日期函数,逻辑运算函数,其他函数)
- 向文件中追加字符串函数
- SQL Server 字符串函数速查
- Visual Basic中的常用字符串函数
- C语言字符串函数大全