# ***********************************************字符串常见的方法集合***************************************************
# 首字母大写
# a = 'aLex'
# v = a.capitalize()
# 把大写字母转化成小写字母,包含特殊字符
a = 'aLex'
v = a.casefold()
把大写字母转化成小写字母,只是普通的英文字母
v = a.lower()
判断字符串是否都是小写
v2 = a.islower()
print(v2)
v1 = a.upper()
v2 = a.isupper()
print(v1,v2)
# 设置宽度,并且将内容居中
# 20表示总共的宽度 *代表剩余的占位字符
# a = 'aLex'
# v = a.center(20,'*')
# 设置宽度,内容分别靠左和靠右
# v1 = a.ljust(20,'*')
# v2 = a.rjust(20,'*')
# print(v1,v2)
# 去字符串中去寻找子序列出现的次数
# a = 'alexalex'
# v = a.count('ex')
# 去字符串中去寻找子序列出现的次数,从第五个位置开始寻找
# a = 'alexalex'
# v = a.count('ex',5)
# 去字符串中去寻找子序列出现的次数,从第五个位置开始,到第六个位置结束
# a = 'alexalex'
# v = a.count('ex',5,6)
# 从开始位置往后寻找子序列,并且返回当前的位置(返回-1代表没有找到)
# test = 'alexalex'
v = test.find('ex')
# 从开始位置往后寻找子序列,并且返回当前的位置,如果找不到系统就会报错
# v = test.index('ex')
# 从第五个位置往后寻找子序列,到第8个之前,不包含第8个位置,并且返回当前的位置(返回-1代表没有找到)
# v = test.find('ex',5,8)
# 格式化,将字符串中的占位符替换成指定的字符串
# test = 'I am {name}, age {a}'
# v = test.format(name='alex', a='19')
# 跟上面效果一样,根据占位符出现的位置依次替换
# test = 'I am {0}, age {1}'
# v = test.format('alex', '19')
# 格式化,必须以字典的格式
# test = 'I am {name}, age {a}'
# v = test.format_map({'name':'alex', 'a':19})
# 判断字符串中是否只是包含字母和数字,否则返回false
# test = 'adse123_,.'
# v = test.isalnum()
# print(v)
# 判断字符串中是否只是包含字母和汉字,否则返回false
# v = test.isalpha()
# 判断当前输入是否是数字,第二个和第三个方法比较牛逼,支持特殊字符。第三个方法还支持汉字,但是最常用的是第一个方法
# test = '123'
# v1 = test.isdecimal()
# v2 = test.isdigit(
# v3 = test.isnumeric()
# print(v1,v2,v3)
# 大小转换
# test = 'AlEx'
v = test.swapcase()
# print(v)
# 判断是否是标识符
# test = 'asdfg'
# v = test.isidentifier()
# print(v)
# 是否存在不可显示的字符(打印的时候)\t \n
# test = 'asd\n'
# v = test.isprintable()
# print(v)
# 判断字符串是否全部未空格 返回True或者False
# test = ' sas'
# v = test.isspace()
# print(v)
# test = 'Return True if S is a titlecased string and there is at least one'
# 将字一个字符串转化成标题格式(每个单词的首字母大写)
# v = test.title()
# 判断一个字符串是否是标题格式
# v2 = test.istitle()
# print(v,v2)
# ***********************************非常重要的一个方法***********************************
# 将字符串的每一个元素按照指定的分隔符进行拼接
# test = '明天是周末,可以睡懒觉了'
# j = ' '
# v = j.join(test)
# print(v)
# 移除指定的字符串以及子序列(先按照最多的匹配,没有就返回)
test = 'alexsas'
v1 = test.lstrip('alexws')
v2 = test.rstrip('sas')
v3 = test.strip('alexsas')
print(v1,v2,v3)
# 替换对应的字符串,两个方法配合使用
# v = 'asjhaojhvbdwefalksjoiuwfkoiucn'
# m = str.maketrans('aeiou','12345')
# new_v = v.translate(m)
# print(new_v)
# test = 'asdfgfdsas'
# 按照指定的字符串进行分割,只是到第一次就停止。可以拿到分隔符,缺点:只执行依次
v1 = test.partition('s')
# 按照指定的字符串进行分割,分割全部的。这个方法包含两个参数,第二个参数代表分割的次数 test.split('s', 2)。缺点拿不到分隔符
v2 = test.split('s')
# print(v1,v2)
# 判断字符串的开头和结尾
# test = "asdfgfdsas"
# v1 = test.startswith('as')
# v2 = test.endswith('as')
# print(v1,v2)
# ***********************************************字符串黑魔法集合***************************************************
# 根据索引取出特定的一个字符
test = 'afksahshsha'
# v = test[2]
# 取出特定范围的字符串[左闭右开区间) 切片
# v2 = test[0:3]
# 获取当前字符串的长度
# v = len(test)
# 字符串替换,默认不指定,第三个参数代表替换几个字符串
# v = test.replace('a','sengege',2)
print(v)