我有一个类型为../sometext/someothertext
的字符串,我试图用网站名称http://www.website.com
替换字符串中的..
。替换字符串中的句点(“。”)
在Python中,我所做的是,像这样:
strName = "../sometext/someothertext"
strName.replace("..", "http://www.website.com")
print strName
但我得到的唯一输出是
../sometext/someothertext
我也试着逃离的时段,例如
strName = ../sometext/someothertext
strName.replace("\.\.", "http://www.website.com")
但输出不变。我该怎么做呢?
我不是一个Python的家伙。但是,如果../总是出现在开始处,那么我只需从2开始添加子串并在开始处追加网站文本。我认为这会更快。 –