[英]How to remove/replace strings before and after nth special character in a string?
如何使用Python Replace方法删除第三个_
及其之前的所有字符串以及第四个_
及其之后的所有字符串
st = "the_gis_osm_natural_a_free_1.shp"
您可以用_
分割字符串,然后加入结果:
start, end = 3, 4
filename = "the_gis_osm_natural_a_free_1.shp"
print('_'.join(filename.split("_")[start:end]))
输出量
natural
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.