初学Python字符串封装


#coding=utf-8

# 字符串操作函数

#字符串反转

def ReverseStr (strtext):  
    return strtext[::-1]

#字母小写转大写 Lowtoup

def Lowtoup(strlowtoup):
	return strlowtoup.upper()

#字母大写转小写  Upper case to low

def Uppertolow(struptolow):
	return struptolow.lower()

#删除字符串的首尾空格

def Deletespace(spacestr):
	return spacestr.strip()

#取特征文本右边内容

def GetStrRight(strall,stright):
	if len(strall) <= 0 or len(stright) <= 0:
		return -1
	index = strall.find(stright)
	if index == -1:
	 	return -1
	else:
		return strall[index + len(stright):len(strall)]

#取特征文本左边内容

def GetStrLeft(strall,strleft):
	if len(strall) <= 0 or len(strleft) <= 0:
		return -1
	index = strall.find(strleft)
	if index == -1:
	 	return -1
	else:
		return strall[0:index]

#取特征文本中间内容

def GetStrBetween(stralls,left,right):
	if len(stralls) <= 0 or len(left) <= 0 or len(right) <= 0:
		return -1
	indexleft = stralls.find(left)
	indexright = stralls.rfind(right)
	if indexleft == -1 or indexright == -1:
		return -1
	else:
		return stralls[indexleft + len(left):indexright]



你可能感兴趣的:(python)