链接: https://pan.baidu.com/s/1smuD9Pb 密码: t8ir
# 1 find sub string "jeap" and pos
# 2 judge some string have any sub string
# tips: double cycle
# hello jeapedu.com jealop
# jeap
# 3 extract website
# s = "welcome to visit my website http://www.baidu.com hehe! or http
# ://www.163.com or http://www.sohu.com"
# extract website sub string baidu 163 sohu
# head = "www" -> ph
# tail = ".com" -> pt
s = "welcome to visit my website x.com http://3.org http://www.baidu.com a.com cx.com hehe! or http://www.163.com or http://www.sohu.com"
head = "http://"
tail = ".com"
ph = 0
preh = 0
pt = 0
i = 0
while i < len(s):
j = 0
ch = 0
while j < len(head) and i + j < len(s):
if s[i + j] == head[j]:
ch += 1
j += 1
if ch == len(head):
ph = i
print("ph =", ph, end=' ')
j = 0
ct = 0
while j < len(tail) and i + j < len(s):
if s[i + j] == tail[j]:
ct += 1
j += 1
if ct == len(tail):
pt = i
print("pt =", pt, end=' ')
# when found tail, print it
# print(s[ph + len(head) : pt + len(tail)])
if ph < pt and preh != ph:
k = ph
dns = ""
while k < pt + len(tail):
dns += s[k]
k += 1
preh = ph # 暂存上次的头
print(dns)
i += 1
s = "hello jeapedu.com"
t = ""
k = 6
while k < 13:
t += s[k]
k += 1
print(s)
print(t)