[英]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.