链接: https://pan.baidu.com/s/1kVW3vG7 密码: 7qcn
# 1 delete black space first and last
# idem
# 2 judge username is ok
# isalpha() isdigit() isalnum() isspace()
# 3 s = "http://www.baidu.com rul http://www.sohu.com rli http://www.ifeng.com heh"
# use str.find to find sub string "http~com"
# http => posh
# com => posc
# 2 judge username is ok
s = "uakd"
i = 0
count = True
while i < len(s):
if not s[0].isalpha():
count = False
break
if s[i].isspace():
count = False
break
i += 1
print(count)
# 3 s = "http://www.baidu.com rul http://www.sohu.com rli http://www.ifeng.com heh"
# use str.find to find sub string "http~com"
# http => posh
# com => posc
s = "http://www.baidu.com rul http://www.sohu.com rli http://www.ifeng.com heh"
head = "http://"
tai = ".com"
posh = 0
post = 0
while s.find(head, posh) != -1:
posh = s.find(head, posh)
post = s.find(tail, post)
print(i, posh, post)
print(s[posh : post + len(tail)])
posh += len(head)
post += len(tail)
s = "http://www.jeapedu.com http://chinaswift.com http://www.chinagame.com http://www.163.com"
h = "http"
c = ".com"
posh = -len(h)
posc = -len(c)
i = 0
while i < s.count(h):
posh = s.find(h, posc + len(c))
posc = s.find(c, posh + len(h))
print(i, posh, posc, s[posh : posc + len(c)])
i += 1