搜索替换操作 [英] Search and replace operation
本文介绍了搜索替换操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含 URL 值的列表,例如:
I have a list which has URL values like:
http://farm6.static.flickr.com/5149/5684108566_aed8b9b52d_s.jpg
如何将所有出现的 _s
最后更改为 _m
?
How can I change the _s
in the end to _m
for all occurrences?
推荐答案
试试这个:
str = "http://farm6.static.flickr.com/5149/5684108566_aed8b9b52d_s.jpg"
str = str.replace("_s","_m")
如果您想确保只有 las 部分被更改并且您知道所有都是 .jpg
文件,您可以使用:
If you want to be sure that only the las part is changed and you know all are .jpg
files you can use:
str = "http://farm6.static.flickr.com/5149/5684108566_aed8b9b52d_s.jpg"
str = str.replace("_s.jpg","_m.jpg")
提供更多上下文并避免更改网址中间的内容.
To give some more context and avoid changes on the middle of the url.
这篇关于搜索替换操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文