python 实现字符串的切片功能
2024-09-12 20:20:35
'''string切片'''
def string_split(stringone,split):
m = []
if type(split)!=str:
return False
if split not in stringone :
m.append(stringone)
return m
if type(stringone)!=str:
return False
if not split:
m.append(stringone)
return m
else:
h=0
l=0
for i in range(len(stringone)):
if stringone[i]==split:
if i==0 and h==0:
n = (stringone[0])
elif h>0:
n=stringone[l:i]
else:
n=stringone[0:i]
if i==len(stringone)-1:
c = stringone[len(stringone)-1]
elif h>0 :
c=stringone[-1]
else:
c=''
if len(n)!=0 :
m.append(n)
if len(c)!=0:
m.append(c)
i += 1
h += 1
l= i
else:
i+=1
return m
print(string_split('12,22,11',split='1,'))
最新文章
- HTML块级元素
- python读取excel数据,并可视化展现
- iOS中编写单例类的心得
- 琐碎--选择文件夹(路径)+生产txt格式的log+数据库操作方式
- easyui的combobox下拉框初始化默认值以及保持该值一直显示的方法
- [原创]EnterpriseDB测试key申请方法
- 1050 数的计数 c语言实现
- Swift2.0新特性
- 操作12864(ST7920控制器)
- Swift String 一些常用方法
- java特权制度设计篇
- mysql命令[转]
- Mybash的实现
- centos6.5搭建hadoop完整教程
- canvas20181114
- python 模块之-time
- 关于trim,ltrim ,rtrim 的 移除问题
- Spring Cloud之注册中心搭建
- spring boot映射静态资源.
- 获取转UTF8的字符串